43 lines
1.4 KiB
Prolog
43 lines
1.4 KiB
Prolog
% "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,
|
|
all_distinct([Nineteen, Twentyone, Twentyfive, Thirty, Thirtyeight]),
|
|
all_distinct([Collision, Explosion, Kidnapping, Robbery, Vandalism]),
|
|
all_distinct([Hat, Jacket, Sunglasses, Tie, Turtleneck]),
|
|
all_distinct([Bat, BrokenBottle, Gun, Knife, Sword]),
|
|
all_distinct([Phone, Purse, Suitcase, Violin, Watch]),
|
|
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.
|