Example Nth Fibonacci Number
ASnake Documentation
Calculates the Fibonacci sequence up to a given nth number.
Code:
fib does
g is ((5**0.5)+1)/2
return ((g**n)-(-1/(g**n)))/(5**0.5)
from int n
int nth = 69
loop nth i then i to fib to print
Result:
0.8944271909999159
1.0
1.3416407864998738
2.0
3.130495168499706
5.000000000000001
8.049844718999244
13.000000000000002
21.01903898849803
34.00000000000001
55.00727224649484
89.00000000000003
144.00277775098652
233.00000000000006
377.0010610064647
610.0000000000003
987.0004052684077
1597.000000000001
2584.0001547987586
4181.000000000003
6765.000059127868
10946.000000000007
17711.000022584845
28657.000000000022
46368.000008626674
75025.00000000006
121393.00000329518
196418.00000000017
317811.00000125886
514229.00000000047
832040.0000004816
1346269.0000000012
2178309.000000186
3524578.0000000037
5702887.000000076
9227465.000000011
14930352.000000045
24157817.000000026
39088169.00000006
63245986.00000007
102334155.00000013
165580141.00000024
267914296.00000036
433494437.0000006
701408733.0000011
1134903170.0000017
1836311903.0000026
2971215073.000005
4807526976.000008
7778742049.000013
12586269025.00002
20365011074.000034
32951280099.000053
53316291173.00009
86267571272.00015
139583862445.00024
225851433717.00043
365435296162.0007
591286729879.0012
956722026041.0018
1548008755920.003
2504730781961.005
4052739537881.0083
6557470319842.014
10610209857723.021
17167680177565.037
27777890035288.062
44945570212853.09
72723460248141.17