From 3446fdd913b74cf6463c48e751ccdb487f02ce2f Mon Sep 17 00:00:00 2001 From: rhiannon morris <rhi@rhiannon.website> Date: Mon, 25 Nov 2024 15:15:56 +0100 Subject: [PATCH] first --- metro.pl | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 metro.pl 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.