Greatest common divisor: Difference between revisions

Content added Content deleted
(→‎{{header|Nial}}: It is a shame to use variables in such a beautiful language.)
Line 298: Line 298:
=2
=2


defining it separately
defining it for arrays
# red is the reduction operator for a sorted list
gcd is operation m n { while m ~= 0 do g := m ; m := n mod m ; n := g ; endwhile ; g }
# one is termination condition
|gcd 6 4
red is cull filter (0 unequal) link [mod [rest, first] , first]
=2
one is or [= [1 first, tally], > [2 first, first]]
gcd is fork [one, first, gcd red] sort <=

Using it
|gcd 9 6 3
=3


=={{header|OCaml}}==
=={{header|OCaml}}==