Frodo still has some reservations about leaving the Shire and saving the world at Mount Doom....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
Python 3 code def checkpointpossiblesegmentsintialenergynummuffins totalenergyintialenergy2nummuffin... View the full answer
Related Book For
A Survey of Mathematics with Applications
ISBN: 978-0134112107
10th edition
Authors: Allen R. Angel, Christine D. Abbott, Dennis Runde
Posted Date:
Students also viewed these operating system questions
-
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers...
-
A single wire ACB of length 2 m passes through a ring at C that is attached to a sphere which revolves at a constant speed v in the horizontal circle shown. Knowing that 1 = 60? and 2 = 30? and that...
-
To shorten the time it takes him to make his favorite pizza, a student designed an experiment to test the effect of sugar and milk on the activation times for baking yeast. Specifically, he tested...
-
Find the requested numbers(s) in Problems 1116. Classify the equation as true, false, or open; and if it is open tell whether it is a conditional, identity, or contradiction. a. Three times the sum...
-
Suppose that {v1, v2.... vn} is an orthonormal set in Rn with the standard inner product. Let the matrix A be given by A = [v1 v2 vn]. Show that A is non-singular and compute its inverse. Give...
-
Graph each function. (x) = x 2 + 2
-
Maribel Baltazar was hired by clothing retail merchandiser Forever 21 in 2007. During the hiring process, Baltazar was given an 11-page document to sign, two pages of which contained an arbitration...
-
Kozma Companys chart of accounts includes the following selected accounts. 101 Cash ............... 401 Sales Revenue 112 Accounts Receivable ........ 414 Sales Discounts 120 Inventory ................
-
Defend the following statement: Data and database administration are even more important in the decentralized IS environment than in the centralized one
-
Evaluate the following statements by providing a brief explanation or analysis. (a) The income gap ratio and the head count, as measures of poverty, may lead to very different uses of antipoverty...
-
There is a one to one correspon dence between ordered rooted trees and binary trees. If you start with an ordered rooted tree, T, you can build a binary tree B with an empty right subtree by placing...
-
Under LIFO, which items of inventory are considered the first sold? The first items purchased. The items purchased at the lowest price. The items purchased furthest from the date of sale
-
Stan and Joe have been friends since they met in the sixth grade 30 years ago. Stan owes Joe $500,000. In order to manage the risk of Stan dying prior to the payment of the debt, Joe, a creditor,...
-
The journal entry to recognize a sales discount includes a to Accounts Receivable and a to Sales Revenue. Enter either debit or credit in each blank.
-
In this threaded discussion, complete the following: Begin your discussion with a definition of Gross Domestic Product. Be sure to include a definition of GDP and a statement of the size of GDP in...
-
What is the Smart City Infrastructure ? and is the Smart City Infrastructure application ? how we can use the Smart City Infrastructure application ?
-
1) Transformations on Quadratic Functions. The most basic quadratic function is f(x) = x, which is an upward facing parabola with its vertex at the origin. One way to view quadratic functions is by...
-
An investor sells a European call on a share for $4. The stock price is $47 and the strike price is $50. Under what circumstances does the investor make a profit? Under what circumstances will the...
-
Convert each of the following to a numeral in the base indicated. 23 to base 3
-
Fill in the blanks with an appropriate word, phrase, or symbol(s). A percent is a ratio of some number to ___________ .
-
A square kilometer is a square with length and width both 1 km. How many times larger is a square kilometer than a square dekameter?
-
The unadjusted trial balance of Innovative Computers Pty Ltd on 30 June 2019 is presented below. The following additional information is available. 1. The inventories as of 30 June 2019 were as...
-
Basic Chemicals Ltd produces a highly flammable chemical product. The company experienced a flood on 1 April 2019 that destroyed its entire work in process inventory but did not affect the raw...
-
Moore Manufacturing Pty Ltd makes refrigerators and is trying to determine the cost of its ending work in process. The accountant has put together the following data for the year ended 30 June 2019....
Study smarter with the SolutionInn App