Question: 13 Eggs Problem A tortoise and the hare saw 13 Easter eggs in the yard. Both the tortoise and the hare wanted all of the
13 Eggs Problem
A tortoise and the hare saw 13 Easter eggs in the yard. Both the tortoise and the hare
wanted all of the eggs for themselves, so they decided to divide them up among themselves. They would alternate turns and in each turn one to three eggs would be taken. If more than 3 eggs are selected, the selection was illegal and the selection should be made again. They agreed that whichever one took the last egg would be able to keep all of the 13 eggs. The tortoise, being the slowest, was allowed to have the first turn.
First Set of Data: The turns were as follows:
Tortoise Hare Eggs Left
13
1 12
2 10
2 8
1 7
3 4
3 1
1 0
Winner is : Tortoise
Second Set of Data: The turns were as follows:
Tortoise Hare Eggs Left
13
2 11
2 9
1 8
3 5
2 3
3 0
Winner is : Hare
Third Set of Data: The turns were as follows:
Tortoise Hare Eggs Left
13
2 11
2 9
5 ERROR MESSAGE
3 6
2 4
3 1
2 ERROR MESSAGE
1 0
Winner is : Hare
Flag Controlled Loop 13 Eggs Problem
Write the program described BELOW
Use the file egggame.cpp to get started with this
exercise.
ADD to your c++ program as a comment the output from executing your program.
USE the 3 sets of data given with the problem description.
Modify the 13 eggs problem.
Write a function that makes the selection for the Tortoise.
The prototype for the function is: int tortoisePick(int numberEggs, int harePicked)
There is a strategy that you can use so that the Tortoise always wins.
When the function is called, if numberEggs is equal to 13,
the tortoise is making the first selection. If
numberEggs is not equal to 13 , the hare has
made a selection and the hares selection was passed
as the second parameter, harePicked.
The return value is the number of eggs that the Tortoise selects.
Hint: After the hare picks, if the tortoise makes a selection so that the sum of
both picks is 4, then the tortoise will always be the winner, since 12 is evenly
divisible by 4.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
