all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
22
Task/Zebra-puzzle/Prolog/zebra-puzzle.pro
Normal file
22
Task/Zebra-puzzle/Prolog/zebra-puzzle.pro
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
select([A|As],S):- select(A,S,S1),select(As,S1).
|
||||
select([],_).
|
||||
|
||||
next_to(A,B,C):- left_of(A,B,C) ; left_of(B,A,C).
|
||||
left_of(A,B,C):- append(_,[A,B|_],C).
|
||||
|
||||
zebra(Owns, HS):- % color,nation,pet,drink,smokes
|
||||
HS = [h(_,norwegian,_,_,_),_,h(_,_,_,milk,_),_,_],
|
||||
select( [h(red,englishman,_,_,_),h(_,swede,dog,_,_),h(_,dane,_,tea,_),
|
||||
h(_,german,_,_,prince)], HS),
|
||||
select( [h(_,_,birds,_,pallmall),h(yellow,_,_,_,dunhill),
|
||||
h(_,_,_,beer,bluemaster)], HS),
|
||||
left_of( h(green,_,_,coffee,_),h(white,_,_,_,_), HS),
|
||||
next_to( h(_,_,_,_,dunhill), h(_,_,horse,_,_), HS),
|
||||
next_to( h(_,_,_,_,blend), h(_,_,cats, _,_), HS),
|
||||
next_to( h(_,_,_,_,blend), h(_,_,_,water,_), HS),
|
||||
next_to( h(_,norwegian,_,_,_), h(blue,_,_,_,_), HS),
|
||||
member( h(_,Owns,zebra,_,_), HS).
|
||||
|
||||
:- zebra(Who, HS), maplist(writeln,HS), nl, write(Who), nl, nl, fail
|
||||
;
|
||||
write('No more solutions.').
|
||||
Loading…
Add table
Add a link
Reference in a new issue