Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Frodo still has some reservations about leaving the Shire and saving the world at Mount Doom. In particular, he's not sure if he's going
Frodo still has some reservations about leaving the Shire and saving the world at Mount Doom. In particular, he's not sure if he's going to have enough food to make it from one checkpoint to the next. Write a function check_points possible () that tells us (returns) how many checkpoints Frodo will be able to make, given his starting energy and amount of food he is carrying. The function takes arguments in the following order: segments: a list of integers that tell us the travel times between checkpoints, in days initial_energy: an integer indicating Frodo's energy in terms of the number of days he can travel without eating any more food num_muffins: an integer indicating how many muffins Frodo has in his knapsack. Each magical Elven muffin gives him enough energy to travel for 2 days. The function computes and returns the number of days Frodo will be able to travel, given the arguments provided. As Frodo passes through a checkpoint, he loses an amount of energy equal to the length of the segment. Some notes: 1. Assume that Frodo always has enough energy to reach the first checkpoint. 2. Ensure that after the last checkpoint, Frodo has at least one day's worth of energy to climb to the peak of Mount Doom. If not, then the last checkpoint is not counted in the total. An example of this is given below. 3. For some test cases, Frodo has more than sufficient energy to reach all the checkpoints. 4. Assume that there are always at least two checkpoints. Example: for the inputs [3, 2], 5, 4, Frodo needs to cross two checkpoints, starting with 5 energy and 4 muffins. Frodo eats the muffins, thereby giving him an additional 4 2 = 8 energy. So now he has 13 total energy. Note that 13-3-2 = 8, which means that Frodo has more than enough energy to make it to Mount Doom. The function will returns 2 because he made it through both checkpoints. Another example: for the inputs [3, 2], 5, 0, Frodo needs to cross two checkpoints, starting with 5 energy and 0 muffins. Note that 5-3-2=0, which means that Note #2 applies. Therefore, the function will return 1, not 2. Function Arguments [3, 2, 8], 4, 6 [3, 5, 4, 11, 4, 3 [3, 5, 4, 1], 0, 3 [3, 5, 4, 11, 4, 0 [1, 2, 2], 1, 2 [1, 2, 2], 1, 2 [9, 6, 10, 1, 7, 10, 9, 8, 51, 1, 13 [2, 1, 1, 5, 6, 8, 2, 91, 1, 9 [5, 8, 8, 51, 2, 6 [7, 2, 5, 71, 3, 7 Return Value WNGANNHHNW 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Python 3 code def checkpointpossiblesegmentsintialenergynummuffins totalenergyintialenergy2nummuffin...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started