Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The numbers game Your code for this problem should be in a file called NumberGame py Here's a fun solitaire game. Imagine that you have

image text in transcribed
The numbers game Your code for this problem should be in a file called NumberGame py Here's a fun solitaire game. Imagine that you have a list of numbers like [18, 3, 5, 15, 4]. Your goal is to select some of those numbers so that you maximize the total sum of the numbers that you select but you don't select two numbers that are next to one another. So, if you select the 10, you can't select the 3 next to it. If you select the 15, you can't select the 5 or the 4 next to it It may be tempting to use a greedy strategy that chooses the largest number first and then removes its neighboring numbers and repeats Unfortunately, this strategy doesn't guarantee selecting numbers with the maximum sum. For example, the list [9, 1e, 91 demonstrates the problem while 10 is the largest value, the optimal solution is to choose the two 9's for a total sum of 18. Your task is to write a function called nunGane(numList) that takes a list of numbers called nunlist as input and returns the maximum score possible choosing numbers from this list but without choosing two adjacent numbers. The order of the nunList is arbitrary you can't make any assumptions about the order Here are some examples: numGame([9, 10, 9]) numGame([1e, 3, 5, 15, 4]) numGame([0, 3, 5, 8, 41) 18 25 19

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions