Skip to content

Instantly share code, notes, and snippets.

@paniq
Last active July 1, 2024 14:50
Show Gist options
  • Save paniq/959537616752fee160422e0ef8f88d09 to your computer and use it in GitHub Desktop.
Save paniq/959537616752fee160422e0ef8f88d09 to your computer and use it in GitHub Desktop.
L(23,1).
L(2,75).
L(5,75).
L(60,90).
L(5,101).
L(60,3).
L(707,66).
L(42,77).
L(5,15).
adj1(?a1,#min(?b1)) :- L(?a1,?a2), L(?b1,?b2), ?a1 < ?b1.
adj2(?a1,?a2,#min(?b2)) :- L(?a1,?a2), L(?a1,?b2), ?a2 < ?b2.
first1(#min(?a1)) :- L(?a1,?a2).
first2(?a1, #min(?a2)) :- L(?a1,?a2).
sorted(0, ?a1, ?a2) :- first1(?a1), first2(?a1, ?a2).
sorted(?i + 1, ?a1, ?a3) :- sorted(?i, ?a1, ?a2), adj2(?a1, ?a2, ?a3).
sorted(?i + 1, ?b1, ?b2) :- sorted(?i, ?a1, ?a2), ~adj2(?a1, ?a2, ?a3), adj1(?a1, ?b1), first2(?b1, ?b2).
@export sorted :- csv{resource = ""}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment