'||''''| || '|| ||
|| . ... || ... ... .. ... .... .... .... ...
||''| || ||' || .| '|. || || '' .|| .| '' .| '' ||
|| || || | || || || || .|' || || || ||
.||. .||. '|...' '|..|' .||. ||. '|..'|' '|...' '|...' .||.
A CLI-based project for calculating Fibonacci numbers using various algorithms. It supports multiple approaches, including recursion, iteration, memoization, and mathematical formulas.
- Calculate Fibonacci numbers using different algorithms.
- Compare performance of algorithms with benchmarking.
- Interactive CLI or direct command-line arguments.
- View descriptions of all available algorithms.
- Lightweight and easy to use.
Before running this project, ensure that you have the following installed:
- Node.js: Version 20.18.1 or higher.
- Yarn: Version 1.22.22 or higher.
To install yarn
, run:
npm install -g yarn
To install project dependencies, run:
yarn install
Run the project using:
yarn start
You can pass arguments directly for quick calculations or use interactive mode.
[algorithm] [number]
: Specify the algorithm and the Fibonacci number to calculate.-h
/--help
: Display usage instructions.-l
/--list
: List all available algorithms with descriptions.
-
Interactive Mode:
yarn start
Prompts you to select an algorithm and input a Fibonacci number.
-
Direct Calculation:
yarn start fib_recursive 10
Calculates the 10th Fibonacci number using the naive recursive algorithm.
-
List Available Algorithms:
yarn start -l
Displays all supported algorithms with descriptions.
-
Help:
yarn start -h
Displays usage information.
Run yarn start -l
to see the full list of algorithms. Below are the included algorithms:
Algorithm | Description |
---|---|
fib_recursive |
A straightforward but inefficient recursive approach. |
fib_loop |
An iterative method with linear time complexity. |
fib_array |
A recursive approach that uses caching to improve performance. |
fib_binet_full |
Uses a mathematical formula for constant-time computation. |
fib_binet_simple |
A simplified version of Binet's formula with rounding. |
fib_matrix |
Uses matrix exponentiation for efficient computation. |
To ensure code quality, run the linter:
yarn eslint