Fibonacci_memoized

Run Settings
LanguagePython
Language Version
Run Command
def fib(num, memo): if memo == []: memo = [None for _ in range(num+1)] if num == 0: result = 0 elif num == 1 or num == 2: result = 1 elif memo[num] != None: result = memo[num] else: result = fib(num-1, memo) + fib(num-2, memo) memo[num] = result return result print("Hello World!") memo = [] sample1 = 5 result1 = fib(sample1, memo) print(f"result1: {result1}") assert(result1 == 5) memo = [] sample2 = 7 result2 = fib(sample2, memo) print(f"result2: {result2}") assert(result2 == 13) memo = [] sample3 = 9 result3 = fib(sample3, memo) print(f"result3: {result3}") assert(result3 == 34) print("good bye world")
Editor Settings
Theme
Key bindings
Full width
Lines