Last active
March 21, 2019 15:53
-
-
Save artisandhq/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.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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