Documentation
¶
Overview ¶
Package lucas is a library for generating Lucas sequence and counting Nth number of Lucas sequence. There are many sequences supported (see example.go)
- Fibonacci numbers - Lucas numbers - Pell numbers - Counting numbers - Jacobsthal numbers - Generalized Lucas sequences by setting two (P and Q) parameters
This library supports big numbers and return big.Int pointer(s)
Example:
fib9 := lucas.GenerateFibonacci(10) fmt.Println(fib9[9].Int64()) // 34 fib10 := lucas.NthFibonacci(10) fmt.Println(fib10.Int64()) // 55
Index ¶
- func GenerateCounting(n uint) []*big.Int
- func GenerateFibonacci(n uint) []*big.Int
- func GenerateJacobsthal(n uint) []*big.Int
- func GenerateJacobsthalLucas(n uint) []*big.Int
- func GenerateLucas(n uint) []*big.Int
- func GeneratePell(n uint) []*big.Int
- func GeneratePellLucas(n uint) []*big.Int
- func GenerateSequenceU(p int64, q int64, n uint) []*big.Int
- func GenerateSequenceV(p int64, q int64, n uint) []*big.Int
- func NthCounting(n uint) *big.Int
- func NthFibonacci(n uint) *big.Int
- func NthJacobsthal(n uint) *big.Int
- func NthJacobsthalLucas(n uint) *big.Int
- func NthLucas(n uint) *big.Int
- func NthPell(n uint) *big.Int
- func NthPellLucas(n uint) *big.Int
- func NthSequenceU(p int64, q int64, n uint) *big.Int
- func NthSequenceV(p int64, q int64, n uint) *big.Int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateCounting ¶
GenerateCounting returns first n counting numbers (0 to n-1) e.g. [0 1 2 3 4 5 6 7 8 9 10]
func GenerateFibonacci ¶
GenerateFibonacci returns first n Fibonacci numbers (F[0] to F[n-1]) e.g. [0 1 1 2 3 5 8 13 21 34 55]
func GenerateJacobsthal ¶
GenerateJacobsthal returns first n Jacobsthal numbers (J[0] to J[n-1]) e.g. [0 1 1 3 5 11 21 43 85 171 341]
func GenerateJacobsthalLucas ¶
GenerateJacobsthalLucas returns first n Jacobsthal-Lucas (companion Jacobsthal) numbers (j[0] to j[n-1]) e.g. [2 1 5 7 17 31 65 127 257 511 1025]
func GenerateLucas ¶
GenerateLucas returns first n Lucas numbers (L[0] to L[n-1]) e.g. [2 1 3 4 7 11 18 29 47 76 123]
func GeneratePell ¶
GeneratePell returns first n Pell numbers (P[0] to P[n-1]) e.g. [0 1 2 5 12 29 70 169 408 985 2378]
func GeneratePellLucas ¶
GeneratePellLucas returns first n Pell-Lucas (companion Pell) numbers (Q[0] to Q[n-1]) e.g. [2 2 6 14 34 82 198 478 1154 2786 6726]
func GenerateSequenceU ¶
GenerateSequenceU returns first n numbers of first kind of Lucas Sequence (U[0] to U[n-1]) Choose this sequence to get starting U[0] = 0, U[1] = 1 Choose P, Q so that U[n] = P*U[n-1] - Q*U[n-2] Complexity: O(n)
func GenerateSequenceV ¶
GenerateSequenceV returns first n numbers of second kind of Lucas Sequence (V[0] to V[n-1]) Choose this sequence to get starting V[0] = 2, V[1] = P Choose P, Q so that V[n] = P*V[n-1] - Q*V[n-2] Complexity: O(n)
func NthCounting ¶
NthCounting returns n-th counting number (zero-indexed) e.g. N[10] = 10
func NthFibonacci ¶
NthFibonacci returns n-th Fibonacci number (zero-indexed) e.g. F[10] = 55
func NthJacobsthal ¶
NthJacobsthal returns n-th Jacobsthal number (zero-indexed) e.g. J[10] = 341
func NthJacobsthalLucas ¶
NthJacobsthalLucas returns n-th Jacobsthal-Lucas (companion Jacobsthal) number (zero-indexed) e.g. j[10] = 1025
func NthPellLucas ¶
NthPellLucas returns n-th Pell-Lucas (companion Pell) number (zero-indexed) e.g. Q[10] = 6726
func NthSequenceU ¶
NthSequenceU returns n-th number of first kind of Lucas Sequence (zero-indexed) It is optimized with fast-doubling and thread-safe memoization to support larger n numbers Choose this sequence to get starting U[0] = 2, U[1] = P Choose P, Q so that U[n] = P*U[n-1] - Q*U[n-2] Complexity: O(log n)
func NthSequenceV ¶
NthSequenceV returns n-th number of second kind of Lucas Sequence (zero-indexed) It is optimized with fast-doubling, bin-exp, and thread-safe memoization to support larger n numbers Choose this sequence to get starting V[0] = 2, V[1] = P Choose P, Q so that V[n] = P*V[n-1] - Q*V[n-2] Complexity: O(log n)
Types ¶
This section is empty.