简体   繁体   中英

Solving ship puzzle using prolog

I need to solve the following problem using prolog.
These are the facts provided.

1. The Greek ship leaves at six and carries coffee.
2. The Ship in the middle has a black chimney.
3. The English ship leaves at nine.
4. The French ship with blue chimney is to the left of a ship that carries coffee.
5. To the right of the ship carrying cocoa is a ship going to Marseille.
6. The Brazilian ship is heading for Manila.
7. Next to the ship carrying rice is a ship with a green chimney.
8. A ship going to Genoa leaves at five.
9. The Spanish ship leaves at seven and is to the right of the ship going to Marseille.
10. The ship with a red chimney goes to Hamburg.
11. Next to the ship leaving at seven is a ship with a white chimney.
12. The ship on the border carries corn.
13. The ship with a black chimney leaves at eight.
14. The ship carrying corn is anchored next to the ship carrying rice.
15. The ship to Hamburg leaves at six.

Which ship goes to Port Said? Which ship carries tea?

I search through the web,but I was unable to find a solution with prolog.
So how can I tackle this problem with prolog?
Thank you.

The Zebra puzzle , aka Einstein's Riddle, is a logic puzzle which is to be solved programmatically.

It has several variants, all in the form of the one you posted.

SPOILER ALERT : the following links contain prolog solutions to the puzzle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM