-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfourColors.pl
68 lines (62 loc) · 2.65 KB
/
fourColors.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
neighbours(austria , [czech_republic, germany, hungary, italy, slovenia, slovakia]).
neighbours(belgium , [france, netherlands, luxemburg, germany, united_kingdom]).
neighbours(bulgaria , [romania, greece]).
neighbours(croatia , [slovenia, hungary]).
neighbours(cyprus , [greece]).
neighbours(czech_republic , [germany, poland, slovakia, austria]).
neighbours(denmark , [germany, sweden]).
neighbours(estonia , [finland, latvia, lithuania]).
neighbours(finland , [estonia, sweden]).
neighbours(france , [spain, belgium, luxemburg, germany, italy, united_kingdom]).
neighbours(germany , [netherlands, belgium, luxemburg, denmark, france, austria, poland, czech_republic]).
neighbours(greece , [bulgaria, cyprus]).
neighbours(hungary , [austria, slovakia, romania, croatia, slovenia]).
neighbours(ireland , [united_kingdom]).
neighbours(italy , [france, austria, slovenia]).
neighbours(latvia , [estonia, lithuania]).
neighbours(luxemburg , [belgium, france, germany]).
neighbours(malta , []).
neighbours(netherlands , [belgium, germany, united_kingdom]).
neighbours(poland , [germany, czech_republic, slovakia, lithuania]).
neighbours(portugal , [spain]).
neighbours(romania , [hungary, bulgaria]).
neighbours(slovakia , [czech_republic, poland, hungary, austria]).
neighbours(slovenia , [austria, italy, hungary, croatia]).
neighbours(spain , [france, portugal]).
neighbours(sweden , [finland, denmark]).
neighbours(united_kingdom , [ireland, netherlands, belgium, france]).
colour_countries(Colours) :-
setof(Country/_, X^neighbours(Country,X), Colours),
colours(Colours).
colours([]).
colours([Country/Colour | Rest]):-
colours(Rest),
member(Colour, [green, yellow, red, purple]),
\+ (member(CountryA/Colour, Rest), neighbour(Country, CountryA)).
neighbour(Country, CountryA):-
neig hbours(Country, Neighbours),
member(CountryA, Neighbours).
member(X, [X|_]).
member(X, [_|Tail]):-
member(X, Tail).
% Let us now execute the program by invoking colour_countries/1.
% ?- colour_countries(Map).
%
% Example response:
% Map = [
% austria/yellow,
% belgium/purple, bulgaria/yellow,
% croatia/yellow, cyprus/yellow, czech_republic/purple,
% denmark/yellow,
% estonia/red,
% finland/yellow, france/yellow,
% germany/red, greece/green,
% hungary/red,
% ireland/yellow, italy/red,
% latvia/green, luxemburg/green,
% malta/green,
% netherlands/yellow,
% poland/yellow, portugal/yellow,
% romania/green, slovakia/green, slovenia/green, spain/green, sweden/green,
% united_kingdom/green
% ].