Created
January 15, 2021 17:05
-
-
Save brunnerh/7a057d1ce89f5cc90ae22de381ad6e81 to your computer and use it in GitHub Desktop.
An SWI Prolog solution to the riddle in Dishonored 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- 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