Created
August 21, 2014 19:01
-
-
Save jleeothon/f50a28ffabd221f705ca to your computer and use it in GitHub Desktop.
Prolog: Euclid's greatest common divisor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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