Given two buckets of different size and which bucket to fill first, determine how many actions are required to measure an exact number of liters by strategically transferring fluid between the buckets.
There are some rules that your solution must follow:
Your program will take as input:
Your program should determine:
Note: any time a change is made to either or both buckets counts as one (1) action.
Example: Bucket one can hold up to 7 liters, and bucket two can hold up to 11 liters. Let's say at a given step, bucket one is holding 7 liters and bucket two is holding 8 liters (7,8). If you empty bucket one and make no change to bucket two, leaving you with 0 liters and 8 liters respectively (0,8), that counts as one action. Instead, if you had poured from bucket one into bucket two until bucket two was full, resulting in 4 liters in bucket one and 11 liters in bucket two (4,11), that would also only count as one action.
Another Example: Bucket one can hold 3 liters, and bucket two can hold up to 5 liters. You are told you must start with bucket one. So your first action is to fill bucket one. You choose to empty bucket one for your second action. For your third action, you may not fill bucket two, because this violates the third rule -- you may not end up in a state after any action where the starting bucket is empty and the other bucket is full.
Written with <3 at Fullstack Academy by Lindsay Levine.
Sometimes it is necessary to raise an exception. When you do this, you should always include a meaningful error message to indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. For situations where you know that the error source will be a certain type, you can choose to raise one of the built in error types, but should still include a meaningful message.
This particular exercise requires that you use the raise statement to "throw" a ValueError
. The tests will only pass if you both raise
the exception
and include a message with it.
To raise a ValueError
with a message, write the message as an argument to the exception
type:
raise ValueError("A meaningful error message here.")
Sign up to Exercism to learn and master Python with 17 concepts, 140 exercises, and real human mentoring, all for free.