commit 3446fdd913b74cf6463c48e751ccdb487f02ce2f Author: rhiannon morris Date: Mon Nov 25 15:15:56 2024 +0100 first diff --git a/metro.pl b/metro.pl new file mode 100644 index 0000000..947c442 --- /dev/null +++ b/metro.pl @@ -0,0 +1,38 @@ +% "constraint logic programming over finite domains" --- +% the number stuff. which is the only thing going on +% in this program. oh well +% +% https://www.swi-prolog.org/pldoc/man?section=clpfd +:- use_module(library(clpfd)). + +go :- solution(Vars), labeling([ff], Vars), write(Vars). + +solution_count(N) :- + setof(Vars, (solution(Vars), labeling([ff], Vars)), Res), + length(Res, N). + +solution(Vars) :- + Vars = [Nineteen, Twentyone, Twentyfive, Thirty, Thirtyeight, + Collision, Explosion, Kidnapping, Robbery, Vandalism, + Hat, Jacket, Sunglasses, Tie, Turtleneck, + Bat, BrokenBottle, Gun, Knife, Sword, + Phone, Purse, Suitcase, Violin, Watch], + Vars ins 1..5, + Hat = Purse, + Sunglasses = Explosion, + Jacket = Bat, + adjacent(Watch, Violin), + Watch = Knife, + Thirty = Collision, + Suitcase = Twentyfive, + Gun = 3, + Turtleneck = 1, + Thirtyeight #< Robbery, + adjacent(Vandalism, Twentyfive), + Sword = Nineteen, + Tie = Twentyone, + adjacent(Turtleneck, Phone), + adjacent(Thirtyeight, BrokenBottle). + +adjacent(X, Y) :- X #= Y + 1. +adjacent(X, Y) :- X #= Y - 1.