Skip to content

A small library that generates the Fibonacci sequence and provides a utility to retrieve the nth term.

License

Notifications You must be signed in to change notification settings

nmarton92/fibonacci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fibonacci generator

A small library that generates the Fibonacci sequence and provides a utility to retrieve the nth term.

Console interface

--sequence, -s [start_from_nth]

Prints the Fibonacci sequence starting from start_from_nth.

Parameters

start_from_nthu32 - Represents the index at which to start the sequence.

--binet, -b [nth]

Calculates the nth Fibonacci number using Binet's formula.

Parameters

nthu32 - Represents the index of the desired Fibonacci term.

Using the Library

Iterating through the sequence

use fibonacci::sequence::ConsecutiveTerms;

// Creates an iterator that starts the sequence from the 5th term:
let example = ConsecutiveTerms::new(5);

// The subsequent Fibonacci term is calculated by calling the 'next' method:
example.next();

// Or iterate to the end of the sequence within the 'u32' range using a for loop:
for term in example {
    println!("{}", term);
}

Getting the nth term

use fibonacci::formula::binet_formula;

println!("{}", binet_formula(10));

Limitations

Currently, Fibonacci numbers are limited to the u32 range. The highest supported Fibonacci number is 2,971,215,072 (F(47)).

Motivation

This is my first pet project in Rust. It helps me familiarize myself with the language.

About

A small library that generates the Fibonacci sequence and provides a utility to retrieve the nth term.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages