1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%%
3%% 980202, 980311 Thom Fruehwirth, LMU
4%% computes greatest common divisor of positive numbers written each as gcd(N)
5%%
6%% ported to hProlog by Tom Schrijvers
7
8:- module(gcd,[]).
9
10:- use_module( library(chr)).
11
12:- constraints gcd/1.
13
14gcd(0) <=> true.
15%%gcd(N) \ gcd(M) <=> N=<M | L is M-N, gcd(L).
16gcd(N) \ gcd(M) <=> N=<M | L is M mod N, gcd(L).  % faster variant
17
18/*
19%% Sample queries
20
21gcd(2),gcd(3).
22
23gcd(1.5),gcd(2.5).
24
25X is 37*11*11*7*3, Y is 11*7*5*3, Z is 37*11*5,gcd(X),gcd(Y),gcd(Z).
26
27*/
28
29