|
|
|
|
|
by macintux
3431 days ago
|
|
If you look at the Wikipedia article for Greatest Common Divisor, you see this: gcd(a, 0) = a
gcd(a, b) = gcd(b, a mod b)
That, in effect, is what pattern matching + function heads gives you. You can copy that function directly into ML or Erlang, modulo a couple tiny bits of syntax. gcd(A, 0) -> A;
gcd(A, B) -> gcd(B, A rem B).
|
|