2 个稳定版本
1.0.1 | 2022 年 7 月 2 日 |
---|
#8 in #fibonacci-sequence
17KB
268 行
fibonacci_guru
计算斐波那契数列的第 n 项的工具。它可以计算超过 128 位的项,并记录计算所需的时间。此工具提供动态规划和递归实现的访问。
安装
-
使用 Cargo
cargoinstall fibonacci_guru
-
从 GitHub 发布页面手动下载发布包 页面
使用方法
选项
A tool to calculate the nth term of the fibonacci sequence..
It can calculate terms that are well above 128 bits and will keep track of how long the calculation cost.
This tool provides access to a dynamic programming implementation as well as recursive implementation.
USAGE:
fibonacci_guru [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-b, --both <BOTH> Uses both the dynamic programming and the recursive implementation. Takes the desired
term number, n value, of the Fibonacci sequence.
-d, --dynamic <DYNAMIC> Uses the dynamic programming implementation. Takes the desired term number, n value,
of the Fibonacci sequence.
-l, --limit <LIMIT> Overrides the max recursion call limit by taking a number greater than 0. The default
the limit is 1073741824 which is enough to calculate n=30 of the Fibonacci sequence.
-r, --recursive <RECURSIVE> Uses the recursive implementation. Takes the desired term number, n value, of the
Fibonacci sequence.
示例
$ fibonacci_guru -d 100
Dynamic:
The 100th term of the Fibonacci sequence is 354224848179261915075.
It took 1031 nanoseconds to calculate it.
$ fibonacci_guru -r 10
Recursive:
The 10th term of the Fibonacci sequence is 55.
It took 19430 nanoseconds to calculate it.
$ fibonacci_guru -b 30
Recursive:
The 30th term of the Fibonacci sequence is 832040.
It took 22 miliseconds to calculate it.
Dynamic:
The 30th term of the Fibonacci sequence is 832040.
It took 721 nanoseconds to calculate it.
The Dynamic Programming implementation was 22 miliseconds faster than the Recursive implementation.
$ fibonacci_guru -r 35 -l 34359738368
Recursive:
The 35th term of the Fibonacci sequence is 9227465.
It took 237 miliseconds to calculate it.
依赖项
~2.2–3MB
~51K SLoC