Skip to content

Instantly share code, notes, and snippets.

@stmtk1
Created February 4, 2020 04:05
Show Gist options
  • Save stmtk1/40510b58a2414f1febab21dbbdf1324f to your computer and use it in GitHub Desktop.
Save stmtk1/40510b58a2414f1febab21dbbdf1324f to your computer and use it in GitHub Desktop.
% coloring
adjacent(1, 2).
adjacent(1, 3).
adjacent(1, 4).
adjacent(1, 5).
adjacent(2, 1).
adjacent(2, 3).
adjacent(2, 4).
adjacent(3, 1).
adjacent(3, 2).
adjacent(3, 4).
adjacent(4, 1).
adjacent(4, 2).
adjacent(4, 3).
adjacent(4, 5).
adjacent(5, 1).
adjacent(5, 4).
color(1, red, a).
color(2, blue, a).
color(3, green, a).
color(4, yellow, a).
color(5, blue, a).
conflict(Coloring) :-
adjacent(X, Y),
color(X, Color, Coloring),
color(Y, Color, Coloring).
% children
child(A, B).
child(B, C).
child(B, D).
child(B, E).
child(C, F).
child(G, H).
grandchild(X, Y) :-
child(X, Z),
child(Z, Y).
ancestor(X, Y) :-
child(X, Y).
ancestor(X, Y) :-
child(X, Z),
decendant(Z, Y).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment