Help with Prolog Here is my code fooXYZ Y 0 Z is X fooXYZ X
Help with Prolog:
Here is my code:
foo(X,Y,Z):- Y =< 0, Z is X.
foo(X,Y,Z):- X =< 0, Z is Y.
foo(X,Y,Z):- X >= Y, X1 is (X-2),
Z is (X + foo(X1,Y)).
foo(X,Y,Z) :- X < Y, Y1 is (Y-3),
Z is (Y + foo(X,Y1)).
I need to input foo(5,6) and return 18.
The problem is foo(x,y) = {
x if y<=0
y if x<=0
x + foo(x-2,y) if x>=y
y+foo(x,y-3) if x <y
I think my logic is good, I just don\'t know how to go to the next step and output the answer.
Solution
Try using the following for your foo predicate:
| ?-foo(5,6).
This should use foo and give result
