Created
December 31, 2017 12:19
-
-
Save AhmadElsagheer/6f3d758bf1a6f31db2d1e299e3f62f15 to your computer and use it in GitHub Desktop.
Daily Galaxy New Coverage (CLPFD)
This file contains hidden or 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(clpfd)). | |
reporters(["Corey", "Jimmy", "Lois", "Perry"]). | |
locations(["Bayonne", "New Hope", "Port Charles", "South Amboy"]). | |
events(["30-pound baby", "blimp launching", "skyscraper dedication", "beached whale"]). | |
match():- | |
reporters(R), length(R, N), length(L, N), length(E, N), | |
L ins 1..4, E ins 1..4, all_distinct(L), all_distinct(E), | |
% 1. Reporter of event 1 didn't go to location 2 or 4 | |
element(R1X, E, 1), element(R1Y, L, 2), element(R1Z, L, 4), R1X #\= R1Y, R1X #\= R1Z, | |
% 2. Reporter 2 didn't go to location 3 | |
element(2, L, L2), L2 #\= 3, | |
% 3. Events 2 and 3 were covered by reporter 3 and the reporter in location 3 | |
element(3, E, E3X), element(R3, L, 3), element(R3, E, E3Y), E3X in 2..3, | |
E3X #= 2 #==> E3Y #= 3, E3X #= 3 #==> E3Y #= 2, | |
% 4. Events 3 and 4 were not at location 4 | |
element(R4X, E, 3), element(R4Y, E, 4), element(R4Z, L, 4), R4X #\= R4Z, R4Y #\= R4Z, | |
% 5. Reporter 1 went to location 1 OR event 4 was at location 1 | |
element(R5X, L, 1), element(R5Y, E, 4), element(R5Y, L, L5), | |
R5X #\= 1 #==> L5 #= 1, L5 #\= 1 #==> R5X #==> 1, | |
maplist(label, [L, E]), maplist(match, R, L, E). | |
match(R, L, E):- | |
locations(Ls), events(Es), | |
nth1(L, Ls, Loc), nth1(E, Es, Ev), | |
format("~w covered ~w at ~w~n", [R, Ev, Loc]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment