Skip to content

Instantly share code, notes, and snippets.

@FabienArcellier
Created December 20, 2012 16:20
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 FabienArcellier/4346348 to your computer and use it in GitHub Desktop.
Save FabienArcellier/4346348 to your computer and use it in GitHub Desktop.
Resolve graph path using prolog
arc(b, a, 1).
arc(b, c, 3).
arc(a, d, 4).
arc(c, d, 5).
arc(d, e, 7).
arc(d, f, 6).
ch1(O, D, Longueur) :- arc(O, D, Longueur).
ch1(O, D, Longueur) :- arc(O, N, L0), ch1(N, D, L1), Longueur is L1 + L0.
ch2(O, D, Longueur, [O,D]) :- arc(O, D, Longueur).
ch2(O, D, Longueur, [O|R]) :- arc(O, N, L0), ch2(N, D, L1, R), Longueur is L1 + L0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment