Question: Water Jug Problem ( 5 0 points ) . You are given two jugs of capacity M liters and N liters. You have to use

Water Jug Problem (50 points).
You are given two jugs of capacity M liters and N liters. You have to use these two jugs to measure out P liters
of water. The general solution to the problem is as follows;
1. Fill the A liter jug and empty it into B liter jug.
2. Whenever the A liter jug becomes empty fill it.
3. Whenever the B liter jug becomes full empty it.
4. Repeat the steps till either B liter jug or the A liter jug contains P liters of water.
We can have two solutions depending on whether A is set to M and B is set to N or vice versa.
a) Write an algorithm that implements the above steps. By settng A and B to the different values compute
which of the solutions is the fastest. Remember to include checks for whether the problem cannot be
solved for a particular combinaEon of (M,N, and K) and whether your code is running into a infinite loop
(10 points).
b) Solving the Diophantine equaEon Mx+Ny=K will provide a faster method to find the minimum number of
steps. Develop a code to compute the steps by solving the equation. (10 points).
I need help with part b

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!