4 ms·
Now I immediately turned to library(clpfd). Something along the lines of: Names = [rudolph, dancer... Vars = [Rudolph, Dancer... Vars ins 1..9, all_dif
by Avshalom 4y ago
Now I immediately turned to library(clpfd). Something along the lines of:
Names = [rudolph, dancer...
Vars = [Rudolph, Dancer...
Vars ins 1..9,
all_different(Vars),
Rudolph #> Dancer,
...
...
pairs_keys_values(P,Vars,Names),
keysort(P,S),
write(S).
- tbensky 4y agoI like the clpfd approach too: :- use_module(library(clpfd)). go(L) :- L = [Vixen, Rudolph, Prancer, Dasher, Comet, Dancer, Donder, Blitzen, Cupid], L ins 1..9, % Vixen should be behind Rudolph, Prancer and Dasher, maplist(#>(Vixen),[Rudolph,Prancer,Dasher]), % Vixen should be in front of Dancer and Comet. maplist(#<(Vixen),[Dancer,Comet]), % Dancer should be behind Donder, Blitzen and Rudolph. maplist(#>(Dancer),[Donder,Blitzen,Rudolph]), % Comet should be behind Cupid, Prancer and Rudolph. maplist(#>(Comet),[Cupid,Prancer,Rudolph]), % Donder should be behind Comet, Vixen, Dasher, Prancer and Cupid. maplist(#>(Donder),[Comet, Vixen, Dasher, Prancer,Cupid]), % Cupid should be in front of Comet, Blitzen, Vixen, Dancer and Rudolph maplist(#<(Cupid),[Comet, Blitzen, Vixen, Dancer,Rudolph]), % Prancer should be in front of Blitzen, Donder and Cupid. maplist(#<(Prancer),[Blitzen,Donder,Cupid]), % Blitzen should be behind Cupid Blitzen #> Cupid, % but in front of Dancer, Vixen and Donder. maplist(#<(Blitzen),[Dancer,Vixen,Donder]), % Rudolph should be behind Prancer Rudolph #> Prancer, % but in front of Dasher, Dancer and Donder. maplist(#<(Rudolph),[Dasher,Dancer,Donder]), % Finally, Dasher should be behind Prancer Dasher #> Prancer, % but in front of Blitzen, Dancer and Vixen. maplist(#<(Dasher),[Blitzen,Dancer,Vixen]).