Skip to content

Commit 7007d4d

Browse files
committed
2019.1.29 update more_fib
1 parent 9c597b6 commit 7007d4d

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

fib/fib.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff 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-
3220
if __name__ == "__main__":
3321
x = 47
3422
start = time.time()

fib/more_fib.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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))

0 commit comments

Comments
 (0)