+ 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.
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."
+ 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.
+ 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
+ 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
+ 1
Great effort Jeff. I'd love to try this in Prolog âș
0
Thanks, Xan :) Then go for it đ€