Skip to content

Instantly share code, notes, and snippets.

@theraphim
Created October 29, 2015 16:58
Show Gist options
  • Save theraphim/fe52608dce8560516a64 to your computer and use it in GitHub Desktop.
Save theraphim/fe52608dce8560516a64 to your computer and use it in GitHub Desktop.
gcd(X, Y, G) :- X = Y, G = X, !.
gcd(X, Y, G) :-
X < Y,
Y1 is Y mod X,
(Y1 = 0 -> G = X; gcd(X, Y1, G)), !.
gcd(X, Y, G) :- X > Y, gcd(Y, X, G), !.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment