http://www.perlmonks.org?node_id=757710


in reply to Re^4: Challenge: N Jugs Problem
in thread Challenge: N Jugs Problem

Yes, I have a "seen" hash already. A couple of them. Har. Anyway, I showed that mine works with an easier problem: target jug size 3, other jugs sized 4 and 1. The least water solution is six steps:

000. [ 0/T 0/4 0/1 ] starting state 001. [ 0/T 0/4 1/1 ] fill jug 1 002. [ 1/T 0/4 0/1 ] pour jug 1 into target 003. [ 1/T 0/4 1/1 ] fill jug 1 004. [ 2/T 0/4 0/1 ] pour jug 1 into target 005. [ 2/T 0/4 1/1 ] fill jug 1 006. [ 3/T 0/4 0/1 ] pour jug 1 into target USED 3 units in 6 steps

Fewest steps solution:

000. [ 0/T 0/4 0/1 ] starting state 001. [ 0/T 4/4 0/1 ] fill jug 0 002. [ 0/T 3/4 1/1 ] pour jug 0 into jug 1 003. [ 3/T 0/4 1/1 ] pour jug 0 into target USED 4 units in 3 steps

I've put my code in Re: Challenge: N Jugs Problem