Question: In Problem 6 . 2 you wrote a recursive function for the numbers game. def numGame ( numList ) : ' ' ' takes a

In Problem 6.2 you wrote a recursive function for the numbers game.
def numGame(numList):
'''takes a list of numbers called numList as input and returns the maximum score possible choosing numbers from this list but without choosing two adjacent numbers. The order of the numList is arbitrary - you can't make any assumptions about the order. '''
Your task now is to memoize that function.
Your new function, called memoNumGame(numList, memo), will take as input both a tuple of numbers and a memo dictionary.
When you run this program, you'll pass it in a list of numbers and an initially empty dictionary as shown below:
>>> memoNumGame((10,3,5,15,4),{})
25
>>> T =(4,9,0,5,3,7,2,4,3,3,5,3,9,3,1,1,8,0,7,5,9,6,6,7,9,5,7,2,8,1,9,7,4,8,2,6,6,3,2,1,2,0,4,0,8,2,4,9,2,9,6,0,1,0,9,6,0,7,6,7,6,5,4,6,0,5,2,1,5,7,9,8,8,5,3,8,2,5,3,7,0,6,3,9,5,6,1,8,6,4,0,4,9,7,5,0,0,9,9,2)
>>> memoNumGame(T,{})
292

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!