Skip to content

Instantly share code, notes, and snippets.

@Bachmann1234
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save Bachmann1234/98edab761645ca2b39f0 to your computer and use it in GitHub Desktop.

Select an option

Save Bachmann1234/98edab761645ca2b39f0 to your computer and use it in GitHub Desktop.
Fib playground
from collections import deque
def fibs():
f = deque([0,1], maxlen=2)
while f:
yield f[0]
f.append(f[-1] + f[-2])
def is_fib(candidate):
for fib in fibs():
if candidate == fib:
return "IsFibo"
elif candidate < fib:
return "IsNotFibo"
for _ in range(int(input())):
print(is_fib(int(input())))
def is_fib(candidate, known_fibs=[0,1]):
last_fib = known_fibs[-1]
if candidate == last_fib:
return "IsFibo"
elif candidate < last_fib:
return "IsNotFibo"
else:
next_fib = last_fib + known_fibs[-2]
new_fibs = known_fibs + [next_fib]
return is_fib(candidate, known_fibs=new_fibs)
for _ in range(int(input())):
print(is_fib(int(input())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment