Wednesday, 15 June 2011

Prolog. If Prolog found first solution then it stops finding -


The task is: Determine that numbers A, B, Cn are divisible. For example: (a = 2, b = 3, c = 4, n = 2 is a, a, c).

Then, I have written the following code:

  one (integer, integer) m (integer), integer, integer, integer) classes one (x, n): - 0 = x mode n, write (x). M (a, b, c, n): - a (a, n) m (a, b, c, n): - a (b, n). M (A, B, C, N): - A (C, N) Round M (2,3,4,2)  

But if Prolog got the solution first (my case One = 2) then it stops and displays it but, in my case the answer would be = 2, c = 4. My question is, "how can Prologue examine all the predictions"?

In some cases, finding other solutions may be necessary to start the performance of back tracking is.

Therefore, I rewrite my code:

  An integer (integer, integer) M (integer, integer, integer, integer) classes one ( X, n): - 0 = x mode n, write (x), nl m (a, b, c, n): - a (a, n), unsuccessful m (a, b, c, n): - A (B, N), Fail. M (a, b, c, n): - a (c, n) round m (2,3,4,2)  

No comments:

Post a Comment