Skip to content

Instantly share code, notes, and snippets.

@richardoey
Last active March 21, 2019 15:53
Show Gist options
  • Save richardoey/16027863698b385f0af1eb6e77db399e to your computer and use it in GitHub Desktop.
Save richardoey/16027863698b385f0af1eb6e77db399e to your computer and use it in GitHub Desktop.
Question 3 (Write a function that takes an array of integers as input. For each integer, output the next fibonacci number. Solution that work both cpu and memory efficient are appreciated.)
import time
def recursiveFibonacci(number, fn1, fn2):
fnNext = fn1 + fn2
fn1 = fn2
if number < fnNext:
print(fnNext)
else:
recursiveFibonacci(number, fn1,fnNext)
def main():
number = input("Input number (separate number with comma): ")
arrNum = number.strip().split(",")
fn1 = 1
fn2 = 1
start2 = time.time()
for i in range (len(arrNum)):
recursiveFibonacci(int(arrNum[i]), fn1, fn2)
end2 = time.time()
print("Time Limit Exceeded Recursive: ", end2 - start2)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment