Skip to content

Instantly share code, notes, and snippets.

@jleeothon
Created August 21, 2014 19:01
Show Gist options
  • Save jleeothon/f50a28ffabd221f705ca to your computer and use it in GitHub Desktop.
Save jleeothon/f50a28ffabd221f705ca to your computer and use it in GitHub Desktop.
Prolog: Euclid's greatest common divisor
euclid(A, 0, Z) :- Z is A.
euclid(A, B, Z) :- B > A, euclid(B, A, Z).
euclid(A, B, Z) :- X is A mod B, euclid(B, X, Z).
gcd(A, B, Z) :- euclid(A, B, Z).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment