lucas

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 2 Imported by: 0

README

lucas

Go package to generate and count Nth number of Lucas sequence (Fibonacci, Lucas, Pell, etc.s). Nth counting is optimized

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

Installation

go get github.com/hamonangann/lucas

Contribution

Fork this repository, then open a pull request to improve this project. I welcome any kind of contributions!

If you have any questions, please raise an issue.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCounting

func GenerateCounting(n uint) []*big.Int

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

func GenerateFibonacci(n uint) []*big.Int

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

func GenerateJacobsthal(n uint) []*big.Int

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

func GenerateJacobsthalLucas(n uint) []*big.Int

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

func GenerateLucas(n uint) []*big.Int

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

func GeneratePell(n uint) []*big.Int

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

func GeneratePellLucas(n uint) []*big.Int

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

func GenerateSequenceU(p int64, q int64, n uint) []*big.Int

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

func GenerateSequenceV(p int64, q int64, n uint) []*big.Int

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

func NthCounting(n uint) *big.Int

NthCounting returns n-th counting number (zero-indexed) e.g. N[10] = 10

func NthFibonacci

func NthFibonacci(n uint) *big.Int

NthFibonacci returns n-th Fibonacci number (zero-indexed) e.g. F[10] = 55

func NthJacobsthal

func NthJacobsthal(n uint) *big.Int

NthJacobsthal returns n-th Jacobsthal number (zero-indexed) e.g. J[10] = 341

func NthJacobsthalLucas

func NthJacobsthalLucas(n uint) *big.Int

NthJacobsthalLucas returns n-th Jacobsthal-Lucas (companion Jacobsthal) number (zero-indexed) e.g. j[10] = 1025

func NthLucas

func NthLucas(n uint) *big.Int

NthLucas returns n-th Lucas number (zero-indexed) e.g. L[10] = 123

func NthPell

func NthPell(n uint) *big.Int

NthPell returns n-th Pell number (zero-indexed) e.g. P[10] = 2378

func NthPellLucas

func NthPellLucas(n uint) *big.Int

NthPellLucas returns n-th Pell-Lucas (companion Pell) number (zero-indexed) e.g. Q[10] = 6726

func NthSequenceU

func NthSequenceU(p int64, q int64, n uint) *big.Int

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

func NthSequenceV(p int64, q int64, n uint) *big.Int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL