We don't bite newbies here... much PerlMonks

### Re^5: Challenge: N Jugs Problem

by kyle (Abbot)
 on Apr 15, 2009 at 15:57 UTC ( #757710=note: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re^6: Challenge: N Jugs Problem
by ikegami (Pope) on Apr 15, 2009 at 16:09 UTC

For comparison:

```\$ time perl min_supply.pl 1 4 3
Required supply: 3
6 steps:
S->X
X->Z
S->X
X->Z
S->X
X->Z

real    0m0.011s
user    0m0.016s
sys     0m0.000s

\$ time perl min_steps.pl 1 4 3
3 steps:
S->Y
Y->Z
Z->X

real    0m0.011s
user    0m0.008s
sys     0m0.004s

\$ time perl -e1

real    0m0.002s
user    0m0.000s
sys     0m0.000s

Note that I got a different solution that yours for min steps, but it's has the same number of steps.

Update: I seemed to have imagined that you said yours was slow. Ignore this post.

Create A New User
Node Status?
node history
Node Type: note [id://757710]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2018-03-21 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (270 votes). Check out past polls.

Notices?