Greatest common divisor: Difference between revisions

Content added Content deleted
(→‎Recursive: use the UInt type and the constraint in a proto)
(Undo revision 202937 by Grondilu (talk) not really better on second thought)
Line 2,322: Line 2,322:


===Recursive===
===Recursive===
<lang perl6>proto gcd (UInt $a, UInt $b where $a|$b > 0) {*}
<lang perl6>multi gcd (0, 0) { fail }
multi gcd ($a, 0) { $a }
multi gcd (Int $a, 0) { abs $a }
multi gcd ($a, $b) { gcd $b, $a % $b }</lang>
multi gcd (Int $a, Int $b) { gcd $b, $a % $b }</lang>


===Concise===
===Concise===