Alice has a set of buckets of various sizes, and an unlimited water supply. Her task is to measure an exact amount of water in one of the buckets.
Buckets are unmarked and she only knows their full capacity, which is always an integer e.g. 5 gallons.
Alice is allowed the following operations:
Note that Alice doesn't know how to measure water in any other way, e.g. she can't pour 1/2 of a bucket into another because her measurement would be inaccurate.
Example: buckets have capacity 3 and 5. Alice is asked to measure 4.
Let's denote buckets' contents by a tuple (a, b) where 0 <= a <= 3 and 0 <= b <= 5.
We start with (0, 0) and can follow these steps:
0_0
Your task is to help Alice determine the shortest sequence of steps that gets desired capacity.
Here she took 6 steps to get to 4 gallons of water.