+ 5

[ASSIGNMENT] Water Juck Puzzle đŸ”„

Given a set of 3 jugs of water that have capacities of a, b, and c liters, find the minimum number of operations performed before each jug has x, y, and z liters. Only jug C will start completely filled. An Jug is either: emptied, filled, or water is poured from one jug to another Create a function that, given an array of jug capacities A, B, C and an goal state array x, y, z, returns the minimum number of operations needed to reach the goal state.

11th Apr 2018, 1:48 PM
Jeff Block
Jeff Block - avatar
7 Answers
+ 2
Example: [3, 5, 8], [0, 3, 5] ➞ 2 [1, 3, 4], [0, 2, 2] ➞ 3 [8, 17, 20], [0, 10, 10] ➞ 9 [4, 17, 22], [2, 5, 15] ➞ "No solution." [3, 5, 8], [0, 0, 9] ➞ "No solution."
11th Apr 2018, 1:49 PM
Jeff Block
Jeff Block - avatar
+ 2
Further Infos: The amount of water in a jug can never exceed the capacity of that jug. The total liters in the goal state must be equal to the capacity of jug C.
11th Apr 2018, 1:48 PM
Jeff Block
Jeff Block - avatar
+ 2
" Only jug C will start completely filled. " So does that mean that when we fill Jug A and B it will also count as steps? Can you use a jug with more capacity to fill a jug with less capacity? Which will make: [3, 5, 8], [0, 3, 5] ➞ 4
14th Apr 2018, 9:58 PM
Limitless
Limitless - avatar
+ 2
[3, 5, 8], [0 ,0, 9] -> 7 steps (if you can add water from a bigger to a smaller bucket, fill a bucket and throw out the water from a bucket, initial start is empty for all 3 buckets and you count filling, adding, and throwing out water as steps) [3, 5, 8] [0,0,9] start: 0,0,0 fill C: 0,0,8 C-B: 0,5,3 empty: 0,0,3 fill A: 3,0,3 add: 0,0,6 fill A: 3,0,6 add: 0,0,9
15th Apr 2018, 9:10 AM
Limitless
Limitless - avatar
+ 1
Great effort Jeff. I'd love to try this in Prolog â˜ș
11th Apr 2018, 2:33 PM
Emma
0
Thanks, Xan :) Then go for it đŸ€™
12th Apr 2018, 9:35 AM
Jeff Block
Jeff Block - avatar