3

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?

false
  • 10,264
  • 13
  • 101
  • 209
nicksheen
  • 550
  • 6
  • 23

1 Answers1

2
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
Kintalken
  • 763
  • 5
  • 9
  • 1
    Better use the CSP operator [`#=`](https://eu.swi-prolog.org/pldoc/doc_for?object=%23%3D%20/%202) because with `is/2` the argument on the right must all be known. But with `#=` this need not be the case. – David Tonhofer Nov 09 '20 at 14:07