-
Notifications
You must be signed in to change notification settings - Fork 0
/
fib plot.py
36 lines (31 loc) · 830 Bytes
/
fib plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
from time import time
import numpy as np
import matplotlib.pyplot as plt
sys.setrecursionlimit(100000)
mem = {}
def fib(num):
if num < 0:
raise ValueError("Negative arguments not allowed")
if num in [0,1]:
return num
else:
if num in mem:
return mem[num]
if num not in mem:
mem[num] = fib(num-1) + fib(num-2)
return mem[num]
'''Fibonacci recursive function with memoisation
for easy (speedy) recall when getting to higher numbers'''
# start = time()
# for x in range(900,1001):
# try:
# print(fib(x))
# except:
# print('Can\'t really do that one, mate.')
# break
# raise RecursionError("Poor")
end = time()
# print(end-start, 'secs')
plt.plot([x for x in range(51)], [fib(x) for x in range(51)])
plt.show()