in reply to Re^2: Challenge: N Jugs Problem
in thread Challenge: N Jugs Problem
I wrote my own solution (which I won't post, as several have now been posted) ...
I'd be interested to see that.
I did some more work on mine, and I got to where I thought it should find a minimum water solution, but it ran overnight without finishing.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Challenge: N Jugs Problem
by ikegami (Patriarch) on Apr 15, 2009 at 15:32 UTC | |
I initially had an infinite loop as well. It turned out that my program was investigating the following path: The necessary step to proceed would have increased the necessary supply, but the program was busy investigating options that didn't increase the necessary supply. I ended up using a "seen" hash to avoid states I had already explored. Even using a brute force approach, the program should find the solution instantly (at least for the values previously discussed in this thread) unless there is no answer. My program checks for that condition as follows:
| [reply] [d/l] |
by kyle (Abbot) on Apr 15, 2009 at 15:57 UTC | |
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:
Fewest steps solution:
I've put my code in Re: Challenge: N Jugs Problem | [reply] [d/l] [select] |
by ikegami (Patriarch) on Apr 15, 2009 at 16:09 UTC | |
For comparison:
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. | [reply] [d/l] |
Re^4: Challenge: N Jugs Problem
by JavaFan (Canon) on Apr 19, 2009 at 19:18 UTC | |
I'd be interested to see that.
| [reply] [d/l] |