# Travel Problem

I just started learning prolog and I was trying to solve this problem, but I got stuck.

Four people are traveling to different places on different types of transport.

Their names are: Rachel, John, Mr. Jones and Cindy.

They either went on train, car, plane or ship.

• Mr. Jones hates flying
• Cindy has to rent her vehicle
• John gets seasick

How did they each travel?

I assumed that we have this fatcs based on the given information.

``````%
travel(cinty, car).

travel(mrjones, train).
travel(mrjones, car).
travel(mrjones, ship).

travel(john, car).
travel(john, plane).
travel(john, train).

travel(cindy, car).
travel(cindy, ship).
travel(cindy, plane).
travel(cindy, train).
``````

And I would like to have the possibilities:

Cindy: car
Mr. Jones: train
John: plane
Rachel: ship

Cindy: car
Mr. Jones: ship
John: plane
Rachel: train

Cindy: car
Mr. Jones: ship
John: train
Rachel: plane

Any help would be appreciated!

``````go([R, J, MJ, C]) :-
writeln("Rachel, John, Mr. Jones, Cindy"),
C = car,
dif(MJ, plane),
dif(J, ship),
permutation([train, car, plane, ship], [R, J, MJ, C]).
``````

Result:

``````?- go(Perm).
Rachel, John, Mr. Jones, Cindy
Perm = [train,plane,ship,car] ;
Perm = [plane,train,ship,car] ;
Perm = [ship,plane,train,car] ;
false.
``````
1 Like

Thank you very much!!