Created
January 16, 2020 15:59
-
-
Save yi-jiayu/b6f1c40a6d0f3b14eb3e677763ecf887 to your computer and use it in GitHub Desktop.
Prolog solution to the Zebra Puzzle (https://en.wikipedia.org/wiki/Zebra_Puzzle)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- use_module(library(clpfd)). | |
zebra(Colors, Nationalities, Pets, Beverages, Cigarettes) :- | |
Colors = [Red, Green, Ivory, Yellow, Blue], | |
Nationalities = [English, Spanish, Ukrainian, Norweigian, Japanese], | |
Pets = [Dog, Snails, Fox, Horse, Zebra], | |
Beverages = [Coffee, Tea, Milk, Orange, Water], | |
Cigarettes = [Old, Kools, Chesterfields, Lucky, Parliaments], | |
Colors ins 1..5, | |
Nationalities ins 1..5, | |
Pets ins 1..5, | |
Beverages ins 1..5, | |
Cigarettes ins 1..5, | |
all_different(Colors), | |
all_different(Nationalities), | |
all_different(Pets), | |
all_different(Beverages), | |
all_different(Cigarettes), | |
English #= Red, | |
Spanish #= Dog, | |
Coffee #= Green, | |
Ukrainian #= Tea, | |
Ivory + 1 #= Green, | |
Old #= Snails, | |
Kools #= Yellow, | |
Milk #= 3, | |
Norweigian #= 1, | |
Chesterfields #= Fox - 1 #\/ Chesterfields #= Fox + 1, | |
Kools #= Horse -1 #\/ Kools #= Horse + 1, | |
Lucky #= Orange, | |
Japanese #= Parliaments, | |
Norweigian #= Blue - 1 #\/ Norweigian #= Blue + 1. | |
% zebra(Colors, Nationalities, Pets, Beverages, Cigarettes), label(Pets), label(Beverages). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment