prologzebra-puzzle

Age Constraint Finding


So I have a simpler variation of the Einstein/Zebra puzzle in Prolog.

enter image description here

And I came up with this possible solution:

b_setval(T_age, Var).
friends(L) :- 
    L = [person(A1, B1, T_age), person(A2, B2, C2), person(A3, B3, T_age+3)],
    :
    :
    member(person(_,yang,T_age+3),L),
    member(person(_,_,18),L).

But my query friends(L). - false. only returns false as stated. What am I doing wrong?


Solution

  • After following the answer of @luker, you can check your answer

    friends(L) :-
        % 1
        L = [person(ada, _, Ta), person(ama, _, _), person(ana, _, _)],
        % 2
        member(person(_,_,15), L),
        member(person(_,_,17), L),
        member(person(_,_,18), L),
        % 3
        member(person(_, chang, _), L),
        % 4
        member(person(_, yang, Ty), L), Ty is Ta + 3,
        % 5
        member(person(_, thatcher, 17), L).
    

    Interesting, this produces 2 results, which is weird for this kind of problem.