# Another simple jugfill problem

You have two 4 liter jugs and one 5 liter jug. All of them are empty.

You can fill up a jug to its full capacity, empty it or pour one jug into another one until the jug you pour into is full or the jug you pour from is empty.

Find the shortest sequence of filling, emptying and pouring that results in 2 liters in both 4 liter jugs.

12 steps:
5 0 0 - fill 5
1 4 0 - fill 4A from 5
0 4 1 - empty 5 into 4B
4 0 1 - empty 4A into 5
4 4 1 - fill 4A
5 3 1 - fill 5 from 4A
2 3 4 - fill 4B from 5
2 3 0 - empty 4B
0 3 2 - empty 5 into 4B
3 0 2 - empty 4A into 5
3 4 2 - fill 4A
5 2 2 - fill 5 from 4A

My solution:

I will call the jugs 5 (5l), 4A (4l) and 4B (4l)
Fill 5, then use it to fill 4A. Empty 4A, then put in the remaining 1l from 5.
Fill 5, then use it to fill 4A. Empty 4A, then put in the remaining 2l from 5.
Repeat, for 4B.

• I am sorry, I missed my requirement to find the shortest sequence. I added it to the OP. While your solution is solving the problem, there is a way to get there in less steps. Apr 18, 2020 at 17:12