Greatest common divisor: Difference between revisions

→‎OCaml: simpler variant, avoids division by 0
(Dialects of BASIC moved to the BASIC section.)
(→‎OCaml: simpler variant, avoids division by 0)
Line 4,732:
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec gcd a b = function
if | 0 -> a = 0 then b
| rb -> gcd1gcd b r(a mod b)</syntaxhighlight>
else if b = 0 then a
else if a > b then gcd b (a mod b)
else gcd a (b mod a)</syntaxhighlight>
 
A little more idiomatic version:
<syntaxhighlight lang="ocaml">let rec gcd1 a b =
match (a mod b) with
0 -> b
| r -> gcd1 b r</syntaxhighlight>
 
=== Built-in ===
559

edits