Question: Problem # 3 : Daniel's Pokemon Gacha Game Obsession Daniel is currently playing the hottest mobile game titled Pokemon Super Duper Ultra Ruby Diamond Phantom

Problem #3: Daniel's Pokemon Gacha Game Obsession
Daniel is currently playing the hottest mobile game titled "Pokemon Super Duper Ultra Ruby Diamond Phantom Sapphire Omega Red, Demon's Return". The good thing is that this is a gacha game. (In a gacha game you roll/spin for special units, in this case special Pokemon, using in-game currency. You can also spend real world money to get more rolls). The bad thing is that Daniel is currently addicted to it. Addiction aside, he wants us to help him write a function which determines what kind of Pokemon he will end up getting after using all of his PokeGems (the currency used for rolling).
Complete the function pokerolling, which takes two parameters. The first parameter, named pokegems, indicates the number of PokeGems that Daniel currently possesses. The second parameter, named pokemonpool, is a list of elements that follows the pattern ['Pokemon name', an integer]. Pokemon name indicates the Pokemon that you are currently rolling for, while the integer indicates the number of rolls until you can obtain the Pokemon. As an example: the list ['Sylveon',27, 'Rayquaza' 55, 'Slakoth', 5] tells us that the current Pokemon that the user is rolling for is "Sylveon", indicated as the left-most entry of the list, and after 27 rolls the user will be able to obtain Sylveon and move on to rolling for Rayquaza, and so on, until the Pokemon pool is empty or the user runs out of PokeGems.
Each roll in the Pokemon pool costs 3 PokeGems.
The function pokerolling should return two values, the first value indicating the remaining PokeGems, either from finishing rolling through all of the Pokemon pools, or from running out of PokeGems before winning all the Pokemon. The second value is a list of Pokemon that you have received from the pool.
Let's go over an example.
Suppose we call pokerolling(274,['Sylveon',20, 'Groudon', 70, 'Pikachu', 2]). This tells us that we have a total of 274 PokeGems at the start.
We will be processing the Pokemon pool from left-to-right, so we start with Sylveon, which requires a total of 20 rolls in order to obtain it. We are able to obtain it because we have enough PokeGems to roll 20 times, which gives us a Sylveon in our output. We are left with 214 PokeGems (274-20*3).
Next, since we have enough for obtaining Groudon, we proceed to roll for him. Since we do 70 rolls, each costing us 3 PokeGems, we deduct 210 gems from our total. We add Groudon to our output, and, after taking 210 gems away, we have only 4 PokeGems left.
Again, we will only stop if we run out of PokeGems or the Pokemon pool is empty. Clearly, we can still roll for Pikachu, but only once, and we do not get Pikachu because it requires 2 rolls in total and we can only do 1. This brings us down to 1 PokeGem in total.
Finally, as return value we will be returning 1,['Sylveon', 'Groudon'] because we are left with only 1 PokeGem in the end, but we did get Sylveon and Groudon.
Function Call
Expected Return Value (integer & list pair)
pokerolling(274,['Sylveon',20, 'Bulbasaur', 70, 'Pikachu', 2])
(1,['Sylveon', 'Bulbasaur'])
pokerolling(1089,['Mewtwo',30, 'Rayquaza', 23,
'Lucario', 188, 'Groudon', 55, 'Pikachu', 8])
(177,['Mewtwo', 'Rayquaza', 'Lucario', 'Groudon', 'Pikachu'])
pokerolling(198,['Sylveon',30, 'Pikachu', 8, 'Charizard', 23, 'Lucario', 188])
(0,['Sylveon', 'Pikachu', 'Charizard'])
pokerolling(452,['Sylveon',20, 'Groudon', 110, 'Pikachu', 42])
(2,['Sylveon', 'Groudon'])

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!