Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numerical comparision in Einstein Riddle

My version is interested in the name, age, origin and subject of students.

solve :-
    length(X, 6),                  % there are six students
    member([manuel, 19, _, _], X), % Manuel is 19 years old
    member([_, 20, _, win], X),    % 20 years old student studies win
    ...

But there are rules I don't know how to implement in Prolog. For example:

Oliver is two years older than the math student but two years younger than the student from Washington.

How do I create a rule where I can compare the age like that?

like image 408
nicksheen Avatar asked Nov 23 '25 22:11

nicksheen


1 Answers

member([oliver,OLIVER_AGE,_,_],X) ,
member([_,MATH_AGE,_,math],X) ,
member([_,WASHINGTON_AGE,washington,_],X) ,
OLIVER_AGE is MATH_AGE + 2 ,
OLIVER_AGE is WASHINGTON_AGE - 2
like image 55
Kintalken Avatar answered Nov 25 '25 15:11

Kintalken