springy2003
Instructor
Hi, I have a very simple prolog problem and I am not sure whats wrong. I have to evalute an integer and from this test will pick the right out come. Here is my prolog code.
rule(A,B,C,Z) :- A=<6, rule(one,Z).
rule(A,B,C,Z) :- A>6, rule(2,B,C,Z).
rule(2,B,C,Z) :- B=yes, rule(two,Z).
rule(2,B,C,Z) :- B=no, rule(3,C,Z).
rule(3,C,Z) :- C=yes, rule(three,Z).
rule(3,C,Z) :- C=no, rule(four,Z).
rule(one,'Return 1').
rule(two,'Return 2').
rule(three,'Return 3').
rule(four,'Return 4').
If I have a goal say:
rule(3,yes,yes,Z). for example it returns "Return 1" which is correct.
But if I do something like:
rule(10,no,no,Z). I would expect "Return 4" but what I get is "Return 1". Can someone please help me out here. Thanks
rule(A,B,C,Z) :- A=<6, rule(one,Z).
rule(A,B,C,Z) :- A>6, rule(2,B,C,Z).
rule(2,B,C,Z) :- B=yes, rule(two,Z).
rule(2,B,C,Z) :- B=no, rule(3,C,Z).
rule(3,C,Z) :- C=yes, rule(three,Z).
rule(3,C,Z) :- C=no, rule(four,Z).
rule(one,'Return 1').
rule(two,'Return 2').
rule(three,'Return 3').
rule(four,'Return 4').
If I have a goal say:
rule(3,yes,yes,Z). for example it returns "Return 1" which is correct.
But if I do something like:
rule(10,no,no,Z). I would expect "Return 4" but what I get is "Return 1". Can someone please help me out here. Thanks