Introduction
The well-known "Die Hard with a Vengeance" water jugs puzzle challenges the two heroes to get 4L of water in a 5L container, provided an unlimited supply of water and another container of 3L. This problem has a solution because 4
is less or equal than the largest container and is a multiple of the gcd(5, 3) = 1
as per number theory. The same goes for other combinations of container sizes as long as the Greatest Common Divisor (GCD) requirements are satisfied for a target value.
Task
In one sentence, the task is to brute-force two solutions by filling and emptying two containers as well as transferring amounts between one another for any given container sizes and target value. The brute-force lies on repeatedly transferring amounts from one container to another, refilling the first when it runs out and emptying the second when it fills up, until any of them contain the target value.
The program should make two runs to respectively find two solutions by swapping container positions (i.e., the container receiving water from the other swaps with that one). The container states should be printed throughout all steps (refilling or emptying and transferring water).
This is code golf, so lowest byte count wins.
Examples
Examples follow below for (5, 3, 4)
and (17, 5, 7)
with 4
and 7
being the target values. Comments added for description purposes.
5 3 4
[5, 0] # initial state
[2, 3] # transferring
[2, 0] # emptying
[0, 2] # transferring
[5, 2] # refilling
[4, 3] # transferring, solution found
3 5 4
[3, 0]
[0, 3]
[3, 3]
[1, 5]
[1, 0]
[0, 1]
[3, 1]
[0, 4]
17 5 7
[17, 0] # initial state
[12, 5] # transferring
[12, 0] # emptying
[7, 5] # transferring, solution found
5 17 7
[5, 0]
[0, 5]
[5, 5]
[0, 10]
[5, 10]
[0, 15]
[5, 15]
[3, 17]
[3, 0]
[0, 3]
[5, 3]
[0, 8]
[5, 8]
[0, 13]
[5, 13]
[1, 17]
[1, 0]
[0, 1]
[5, 1]
[0, 6]
[5, 6]
[0, 11]
[5, 11]
[0, 16]
[5, 16]
[4, 17]
[4, 0]
[0, 4]
[5, 4]
[0, 9]
[5, 9]
[0, 14]
[5, 14]
[2, 17]
[2, 0]
[0, 2]
[5, 2]
[0, 7]