Skip to content

Instantly share code, notes, and snippets.

@josd
Created August 1, 2019 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josd/9f65b99b7131c0a2a075d8297ffcdb07 to your computer and use it in GitHub Desktop.
Save josd/9f65b99b7131c0a2a075d8297ffcdb07 to your computer and use it in GitHub Desktop.
Four Color test
:- table four_color/2.
% four color
four_color(Place, Color) :-
neighbours(Place, Neighbours),
member(Color, [red, green, blue, yellow]),
\+ four_color(Place, _),
\+ (member(Neighbour, Neighbours), four_color(Neighbour, Color)).
% map of European Union
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(lithuania, [estonia, latvia, poland]).
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]).
% test run
run :-
( four_color(Country, Color),
portray_clause(four_color(Country, Color)),
fail
; halt
).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment