Skip to content

Instantly share code, notes, and snippets.

@gulbanana
Created June 24, 2022 06:28
Show Gist options
  • Save gulbanana/9f2ba2b584a2e10da3c83ac4b090a053 to your computer and use it in GitHub Desktop.
Save gulbanana/9f2ba2b584a2e10da3c83ac4b090a053 to your computer and use it in GitHub Desktop.
guest(Guests, X) :- member([X, _, _, _, _], Guests).
color(Guests, X, C) :- member([X, C, _, _, _], Guests).
drink(Guests, X, D) :- member([X, _, D, _, _], Guests).
origin(Guests, X, O) :- member([X, _, _, O, _], Guests).
heirloom(Guests, X, H) :- member([X, _, _, _, H], Guests).
position(Guests, X, P) :- nth0(P, Guests, [X, _, _, _, _]).
left_of(Guests, X, Y) :- position(Guests, X, L), position(Guests, Y, R), R is L + 1.
right_of(Guests, X, Y) :- position(Guests, X, R), position(Guests, Y, L), R is L + 1.
next_to(Guests, X, Y) :- left_of(Guests, X, Y).
next_to(Guests, X, Y) :- right_of(Guests, X, Y).
solution(Guests) :-
% The women sat in a row.
length(Guests, 5),
% At the dinner party were Lady Winslow, Doctor Marcolla, Countess Contee, Madam Natsiou, and Baroness Finch.
guest(Guests, winslow),
guest(Guests, marcolla),
guest(Guests, contee),
guest(Guests, natsiou),
guest(Guests, finch),
% They all wore different colors and Lady Winslow wore a jaunty green hat.
color(Guests, winslow, green),
% Baroness Finch was at the far left, next to the guest wearing a white jacket.
position(Guests, finch, 0),
position(Guests, WhiteJacket, 1),
color(Guests, WhiteJacket, white),
% The lady in red sat left of someone in blue.
color(Guests, RedLady, red),
color(Guests, BlueSomeone, blue),
left_of(Guests, RedLady, BlueSomeone),
% I remember that red outfit because the woman spilled her wine all over it.
drink(Guests, RedLady, wine),
% The traveller from Dabokva was dressed entirely in purple.
origin(Guests, DabokvaTraveller, dabokva),
color(Guests, DabokvaTraveller, purple),
% When one of the dinner guests bragged about her War Medal, the woman next to her said they were finer in Dabokva, where she lived.
heirloom(Guests, MedalBraggart, war_medal),
next_to(Guests, MedalBraggart, DabokvaTraveller),
% So Countess Contee showed off a prized Bird Pendant, at which the lady from Baleton scoffed, saying it was no match for her Snuff Tin.
heirloom(Guests, contee, bird_pendant),
origin(Guests, Scoffer, baleton),
heirloom(Guests, Scoffer, snuff_tin),
% Someone else carried a valuable Diamond and when she saw it, the visitor from Karnaca next to her almost spilled her neighbor's absinthe.
heirloom(Guests, SomeoneElse, diamond),
origin(Guests, KarnacaVisitor, karnaca),
drink(Guests, AbsintheNeighbour, absinthe),
next_to(Guests, SomeoneElse, KarnacaVisitor),
next_to(Guests, KarnacaVisitor, AbsintheNeighbour),
% Madam Natsiou raised her whiskey in toast.
drink(Guests, natsiou, whiskey),
% The lady from Dunwall, full of beer, jumped up onto the table, falling onto the guest in the center seat, spilling the poor woman's rum.
origin(Guests, TableJumper, dunwall),
drink(Guests, TableJumper, beer),
not(position(Guests, TableJumper, 2)),
position(Guests, PoorWoman, 2),
drink(Guests, PoorWoman, rum),
% Then Doctor Marcolla captivated them all with a story about her wild youth in Fraeport.
origin(Guests, marcolla, fraeport),
% In the morning, there were four heirlooms under the table: the War Medal, Ring, the Snuff Tin and the Diamond. But who owned each?
heirloom(Guests, _, ring),
writeln(Guests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment