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 |
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 |
|||
⚫ | |||
red is cull filter (0 unequal) link [mod [rest, first] , first] |
|||
⚫ | |||
one is or [= [1 first, tally], > [2 first, first]] |
|||
gcd is fork [one, first, gcd red] sort <= |
|||
Using it |
|||
⚫ | |||
⚫ | |||
=={{header|OCaml}}== |
=={{header|OCaml}}== |