The first application you will complete simulates a fight with the mythical greek hydra. As legend goes, if you were to chop off the head of a hydra, two smaller heads would grow back in its place. In order for our fight to have an end, we will assume that once the size of the targeted head is small enough, no new heads will grow back in its place. The goal of this application is to determine the amount of work required to kill a hydra with a single head, when the size of the head is given as input. Final output would look like this The head bag is Bag[ 3 ] The head bag is Bag[ 2 2 ] The head bag is Bag[ 2 1 1 ] The head bag is Bag[ 2 1 ] The head bag is Bag[ 2 ] The head bag is Bag[ 1 1 ] The head bag is Bag[ 1 ] The head bag is Bag[ ] The number of chops required is 7 Run the program again using 4 for the size of the initial head. The work done should be 15. Run the program again using 5 for the size of the initial head. You should get the computation ended early. Run the program again using 6 for the size of the initial head. You should get the computation ended early. Run the program again using 7 for the size of the initial head. You should get the computation ended early
The first application you will complete simulates a fight with the mythical greek hydra. As legend goes, if you were to chop off the head of a hydra, two smaller heads would grow back in its place. In order for our fight to have an end, we will assume that once the size of the targeted head is small enough, no new heads will grow back in its place. The goal of this application is to determine the amount of work required to kill a hydra with a single head, when the size of the head is given as input.
Final output would look like this
The head bag is Bag[ 3 ]
The head bag is Bag[ 2 2 ]
The head bag is Bag[ 2 1 1 ]
The head bag is Bag[ 2 1 ]
The head bag is Bag[ 2 ]
The head bag is Bag[ 1 1 ]
The head bag is Bag[ 1 ]
The head bag is Bag[ ]
The number of chops required is 7
Run the
Run the program again using 5 for the size of the initial head. You should get the computation ended early.
Run the program again using 6 for the size of the initial head. You should get the computation ended early.
Run the program again using 7 for the size of the initial head. You should get the computation ended early
Trending now
This is a popular solution!
Step by step
Solved in 2 steps