Skip to content

Instantly share code, notes, and snippets.

@brunnerh
Created January 15, 2021 17:05
Show Gist options
  • Save brunnerh/7a057d1ce89f5cc90ae22de381ad6e81 to your computer and use it in GitHub Desktop.
Save brunnerh/7a057d1ce89f5cc90ae22de381ad6e81 to your computer and use it in GitHub Desktop.
An SWI Prolog solution to the riddle in Dishonored 2.
:- use_module(library(lists)).
:- use_module(library(clpfd)).
:- use_module(library(pairs)).
:- use_module(library(apply)).
solution(P, H, Vs) :-
Table = [Persons, Beaverages, Colors, Heirlooms, Origins],
PersonNames = [winslow, marcolla, contee, natsiou, finch],
HeirloomNames = [diamond, tin, ring, pendant, medal],
Persons = [Winslow, Marcolla, Contee, Natsiou, Finch],
Beaverages = [Beer, Absinthe, Wine, Whiskey, Rum],
Colors = [White, Red, Green, Blue, Purple],
Heirlooms = [Diamond, Tin, Ring, Pendant, Medal],
Origins = [Dunwall, Fraeport, Karnaca, Baleton, Dabovka],
pairs_keys_values(P, Persons, PersonNames),
pairs_keys_values(H, Heirlooms, HeirloomNames),
maplist(all_distinct, Table),
append(Table, Vs),
Vs ins 1..5,
Marcolla #= 1,
Natsiou #= Whiskey,
Contee #= Purple,
Winslow #= Diamond,
Finch #= Karnaca,
White #= 2,
Red #= Green - 1,
Red #= Absinthe,
Dunwall #= Blue,
next_to(Tin, Dunwall),
Fraeport #= Pendant,
next_to(Ring, Baleton),
next_to(Baleton, Rum),
Dabovka #= Wine,
Dabovka #\= 3,
Beer #= 3.
next_to(H, N) :- abs(H - N) #= 1.
% Query via the following line, matching the numbers:
% solution(P, H, Vs), label(Vs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment