in reply to Re^3: Challenge: N Jugs Problem
in thread Challenge: N Jugs Problem
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:
$target % Math::Numbers->new($sz_X, $sz_Y)->gcd() == 0 or die("No solution\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Challenge: N Jugs Problem
by kyle (Abbot) on Apr 15, 2009 at 15:57 UTC | |
by ikegami (Patriarch) on Apr 15, 2009 at 16:09 UTC |