In the previous post, Decanting Problems and Dijkstra’s Algorithm, we presented some scipy hackery to solve the Die Hard puzzle:

Two men have a full eight-gallon jug of wine, and also two empty jugs of five and three gallons capacity, respectively. Is it possible (within the restrictions of our problem) to divide the wine equally so each men can have four gallons of wine?

In this post we replicate the same technique, but this time using Julia’s Graphs package. First of all, make sure you have the package installed. If this is not the case, issue in an Ijulia session the command Pkg.add("Graphs"). Once installed, the functions of the package can be readily called.

We are ready to fire Dijkstra’s algorithm on this graph now.

As in the previous solution, we found that the simplest way to divide the wine equally is in 7 steps as follows:

1. Pour 5 gallons of wine into the second jug. $$(3,5,0)$$
2. Pour 3 gallons from the second jug to the third. $$(3,2,3)$$
3. Pour 3 gallons from the third to the first. $$(6,2,0)$$
4. Pour all 2 gallons from the second to the third jug. $$(6,0,2)$$
5. Pour five gallons from the first to the second jug. $$(1,5,2)$$
6. Pour one gallon from the second to the third jug. $$(1,4,3)$$
7. We are technically done, but we may pour now all three gallons from the third jug to the first, for a convenient transportation of the wine. $$(4,4,0)$$