Re: no backtrack




bart demoen wrote:
On Thu, 14 Sep 2006 10:07:45 -0700, Trap D wrote:

Hello
I'm trying to solve a problem : "How can you divide 8L of milk with
three cans of 3, 5 , and 8 L ?"
My code "works" but I get only one solution (and itsn't the best !).
Why don't I get all the solutions ?


For finding the best solution:
try reformulating the problem as a "find-shortest-path-in-a-graph"
problem: the nodes are the contents of the three cans, and two nodes
are connected when you can go from the contents described by the
first node to the contents described by the second node with just the
can manipulations that are allowed.
Once you have done that, you will see how to find all solutions (with or
without a cycle in the graph).

Cheers

Bart Demoen

Thank you Bart for this advise, it's a good idea.
As I will have to build the graph without cycles, I can build it step
by step, finding all the nodes I can get with 1 step, then with 2 steps
..., and when I find the solution, it's inevitably the best solution. Am
I right ?
Now, just for my curiosity, and also to understand Prolog mechanism,
why don't I have back-track ?

Cheers

Joël

.



Relevant Pages

  • Re: no backtrack
    ... I'm trying to solve a problem: "How can you divide 8L of milk with ... without a cycle in the graph). ...
    (comp.lang.prolog)
  • Re: Programming languages for the very young
    ... > physical metaphors, or grounding schemas as Nunez and Lakoff call them. ... > Freshman students invariably ask me why they can't divide a number by ... > into a pile on the table. ... > graph." ...
    (comp.lang.lisp)
  • counting cycles
    ... :> its meaning is perfectly clear and non-controversial. ... If you try to graph it, ... Except that this cycle IS infinite. ... It's hard to know what you even COULD mean by an infinite cycle. ...
    (sci.logic)
  • Re: Floating-Point Divide and Square Root Performance
    ... > It's trivial enough to get the peak FLOPS for multiply and addition ... > units that can give results every cycle. ... > the square root and divide on an architecture like the Itanium 2. ...
    (comp.arch.arithmetic)
  • Re: Finding Euler paths..
    ... > Euler path in a graph taking input as the edges. ... check that there can exist a euler path in the graph. ... [For a Euler cycle, find any old cycle to start ... So, our original path shares no vertices with the first cycle, so we ...
    (comp.programming)