Skip to content

Instantly share code, notes, and snippets.

@passsy
Created October 14, 2013 11:47
Show Gist options
  • Save passsy/6974427 to your computer and use it in GitHub Desktop.
Save passsy/6974427 to your computer and use it in GitHub Desktop.
Not working Prolog solution for Einsteins Riddle Game. http://www.flashanywhere.net/en/actiongames/18189-einsteins-riddle.html/
live(british, red).
pet(swedish, dog).
drink(danish, tea).
nextto(green, white).
house(A, N) :- live(A, green), live(B, white), house(B, M), M < N.
left(green, white).
right(white, greem).
live(X, green) :- drink(X, coffee).
smoke(Z, pallmall) :- pet(Z, bird).
live(X, yellow) :- smoke(X, dunhill).
house(A, 3) :- drink(A, milk).
house(norwegian, 1).
smoke(Z, blends) :- nextto(Z, C), pet(C, cats).
nextto(HouseA, HouseB) :- live(A, HouseA), pet(A, horses), live(B, HouseB), smoke(B, dunhill).
smoke(Z, bluemaster) :- drink(Z, beer).
smoke(german, prince).
live(norwegian, G) :- nextto(G, blue).
smoke(H, blends) :- nextto(H, I), drink(I, water).
nextto(HouseA, HouseB) :- live(NationA, HouseA), live(NationB, HouseB), house(NationA, N), N1 is N - 1, N > 0, house(NationB, N1).
nextto(HouseA, HouseB) :- live(NationA, HouseA), live(NationB, HouseB), house(NationA, N), N1 is N + 1, N < 6, house(NationB, N1).
house(Nation, Number) :- Number > 0, N1 is Number - 1, house(OtherNation, N1), left(OtherNation, Nation).
house(Nation, Number) :- Number < 6, N1 is Number + 1, house(OtherNation, N1), right(OtherNation, Nation).
solution(House, Color, Nation, Drink, Smoke, Pet) :- house(Nation, House), live(Nation, Color), drink(Nation, Drink), smoke(Nation, Smoke), pet(Nation, Pet).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment