A modified version of the Die Hard 3 problem is using 2 jugs

A modified version of the Die Hard 3 problem is using 2 jugs (4 gal and 3 gal) and a water faucet, how do we get exactly 2 gal in the 4 gal jug? Hint: Use breadth first search and recursion with the 2 jugs with weights of 3 and 4. So the problem can be treated as one of reverse engineering. Take any one solution which appeals to you the most, review the code - make sure you understand what is going on each step of the way - and document the solution as pseudo-code. This is a Python question and i need the python code.

Solution

Solution:

Simplify the question and your options. Setting the movie aside for the moment, think of the riddle in its most basic terms. Consider two empty water jugs in your hands. One holds 3 gallons of water, the other holds 5 gallons of water. Two jugs are used to measure exactly 4 gallons of water.

Determine whether to keep the 4 gallons of water. In order to measure out 4 gallons, initially need to put it somewhere. It is not possible to fit it in the 3-gallon jug, which means the right answer must involve getting the right amount of water in the 5-gallon jug.

Know that, like all good riddles, need to have everything for a solution. The solution does not involve bringing in another jug, or eyeballing the water levels perfectly, or finding fractions of jugs. Two jugs and an unlimited supply of water.

Realize that this is, at heart, a simple math problem. Ignore the water and the jugs for a moment if it is still stuck. when it is add or subtract 3\'s and 5\'s to get to 4. Adding water or dumping it out is really just addition and subtraction.

Solution:

Fill the 5-jug up completely. There will be, of course, 5 gallons in the 5-jug,must fill all the gallons up to the top.

Use the water from the 5-jug to fill up the 3-jug. It is left with 3 gallons in the 3-jug and 2 gallons in the 5-jug.

Pour out the 3-gallon jug. Then it is left with nothing in the 3-jug and 2 gallons in the 5-jug.

Transfer the water from the 5-jug to the three jug. Thenleft with 2 gallons in the 3-jug. And nothing in the 5-jug.

Fill up the 5-jug completely. Next have 2 gallons in the 3-jug and 5 in the 5-jug. This means that there is 1 gallon (3.8 L) of space left in the 3-jug.

Use the water from the 5-jug to fill up the 3-jug. Fill up the last gallon of space in the 3-jug with the water from the 5-jug. This leaves with 3 gallons in the 3-jug, and 4 gallons in the 5-jug.

A modified version of the Die Hard 3 problem is using 2 jugs (4 gal and 3 gal) and a water faucet, how do we get exactly 2 gal in the 4 gal jug? Hint: Use bread

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site