Skip to content

Instantly share code, notes, and snippets.

@WillNess
Last active December 28, 2015 19:39
Show Gist options
  • Select an option

  • Save WillNess/7551378 to your computer and use it in GitHub Desktop.

Select an option

Save WillNess/7551378 to your computer and use it in GitHub Desktop.
zebra(X,HS):-
length(HS,5),
member(H1,HS), nation(H1,eng), color(H1,red),
member(H2,HS), nation(H2,spa), owns( H2,dog),
member(H3,HS), drink( H3,coffee), color(H3,green),
member(H4,HS), nation(H4,ukr), drink(H4,tea),
member(H5,HS), smoke( H5,oldgold), owns( H5,snails),
member(H6,HS), smoke( H6,kools), color(H6,yellow),
member(H7,HS), smoke( H7,lucky), drink(H7,orange),
member(H8,HS), nation(H8,jpn), smoke(H8,parlamt),
(append(_,[A,B|_],HS) ; append(_,[B,A|_],HS)), nation(A,nor), color(B,blue),
append(_,[C,D|_],HS), color( C,ivory), color(D,green),
HS=[_,_,E,_,_], drink(E,milk), HS=[F|_], nation(F,nor),
(append(_,[G,H|_],HS) ; append(_,[H,G|_],HS)), smoke( G,chester), owns( H,fox),
(append(_,[I,J|_],HS) ; append(_,[J,I|_],HS)), smoke( I,kools), owns( J,horse),
member(X,HS), owns(X,zebra).
nation(H,N):- memberchk( nation(X), H), X=N.
owns(H,N):- memberchk( owns( X), H), X=N.
smoke(H,N):- memberchk( smoke( X), H), X=N.
color(H,N):- memberchk( color( X), H), X=N.
drink(H,N):- memberchk( drink( X), H), X=N.
20 ?- time((zebra(_X,_),nation(_X,N),writeln(N),false ; true)).
jpn
% 215,809 inferences, 0.090 CPU in 0.090 seconds (100% CPU, 2394430 Lips)
true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment