Skip to content

Instantly share code, notes, and snippets.

@FabienArcellier
Created December 20, 2012 16:20
Show Gist options
  • Select an option

  • Save FabienArcellier/4346348 to your computer and use it in GitHub Desktop.

Select an option

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