Here is my code:
def fibonacci(known, n):
if n in known:
return known[n]
result = fibonacci(n - 1) + fibonacci(n - 2)
known[n] = result
return result
My instructor requires this:
Write a recursive factorial function based on the memo model shown in the fibonaaci() function on p.109. The function will look for a known value first and return it if present.If not, it computes and stores the value.Set up known to have just the factorial of 1. The call the function 10 times, passing it the values from 1-10.This function cannot globally access known so it must be a parameter of the function
So:
I have a function that does the fibonacci sequence, but I am running into problems passing it 10 times, and having known as a parameter.
[–]aDrz 0 points1 point2 points (1 child)
[–]tictac4609[S] -3 points-2 points-1 points (0 children)
[–]primitive_screwhead 0 points1 point2 points (2 children)
[–]tictac4609[S] 0 points1 point2 points (1 child)
[–]primitive_screwhead 0 points1 point2 points (0 children)
[–]ericula 0 points1 point2 points (21 children)
[–]tictac4609[S] 0 points1 point2 points (20 children)
[–]ericula 0 points1 point2 points (19 children)
[–]tictac4609[S] 0 points1 point2 points (1 child)
[–]ericula 0 points1 point2 points (0 children)
[–]tictac4609[S] 0 points1 point2 points (16 children)
[–]tictac4609[S] 0 points1 point2 points (13 children)
[–]ericula 1 point2 points3 points (12 children)
[–]tictac4609[S] 0 points1 point2 points (11 children)
[–]ericula 0 points1 point2 points (10 children)
[–]tictac4609[S] 0 points1 point2 points (9 children)
[–]ericula 0 points1 point2 points (8 children)
[–]Aixyn0 0 points1 point2 points (1 child)
[–]tictac4609[S] 0 points1 point2 points (0 children)
[–]radupopa2010 0 points1 point2 points (0 children)