File tree Expand file tree Collapse file tree 2 files changed +33
-12
lines changed
Expand file tree Collapse file tree 2 files changed +33
-12
lines changed Original file line number Diff line number Diff line change @@ -17,18 +17,6 @@ def cache_fib(n, _cache={}):
1717 return n
1818
1919
20- def pow_fib (n ):
21- return pow (2 << n , n + 1 , (4 << 2 * n ) - (2 << n ) - 1 ) % (2 << n )
22-
23-
24- def ab_fib (n ):
25- a , b = 1 , 1
26- n = n - 2
27- for i in range (n ):
28- a , b = b , a + b
29- return b
30-
31-
3220if __name__ == "__main__" :
3321 x = 47
3422 start = time .time ()
Original file line number Diff line number Diff line change 1+ import time
2+
3+
4+ def pow_fib (n ):
5+ return pow (2 << n , n + 1 , (4 << 2 * n ) - (2 << n ) - 1 ) % (2 << n )
6+
7+
8+ def for_fib (n ):
9+ a , b = 1 , 1
10+ n = n - 2
11+ for i in range (n ):
12+ a , b = b , a + b
13+ return b
14+
15+
16+ def list_fib (n ):
17+
18+ list_f = []
19+ f = 1
20+ list_f .append (f )
21+ list_f .append (f ) # because the fibonacci sequence has two 1's at first
22+ for i in range (n - 2 ):
23+ f = list_f [- 1 ] + list_f [- 2 ] # says that f = the sum of the last two f's in the series
24+ list_f .append (f )
25+ return f
26+
27+
28+ if __name__ == "__main__" :
29+ x = 47
30+ start = time .time ()
31+ res = list_fib (x )
32+ elapsed = time .time () - start
33+ print ("Python Computed fib(%s)=%s in %0.8f seconds" % (x , res , elapsed ))
You can’t perform that action at this time.
0 commit comments