# Travel Problem

**URL:** <https://swi-prolog.discourse.group/t/travel-problem/5330>\
**Category:** Help!\
**Created:** [April 25, 2022, 2:19pm UTC](https://swi-prolog.discourse.group/t/travel-problem/5330 "2022-04-25T14:19:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hvdias](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/hvdias/32/4373_2.png) [@hvdias](https://swi-prolog.discourse.group/u/hvdias)\
**Post date:** [April 25, 2022, 2:19pm UTC](https://swi-prolog.discourse.group/t/travel-problem/5330/1 "2022-04-25T14:19:41Z")

</div>

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.

```prolog
% 
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!

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [April 25, 2022, 5:14pm UTC](https://swi-prolog.discourse.group/t/travel-problem/5330/2 "2022-04-25T17:14:06Z")

</div>

```prolog
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:

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

```

---

<div class="post-metadata">

**Author:** ![hvdias](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/hvdias/32/4373_2.png) [@hvdias](https://swi-prolog.discourse.group/u/hvdias)\
**Post date:** [April 26, 2022, 12:12am UTC](https://swi-prolog.discourse.group/t/travel-problem/5330/3 "2022-04-26T00:12:56Z")

</div>

Thank you very much!!
