Jump to content

Greatest common divisor: Difference between revisions

Added Perl 6.
(Added Perl 6.)
Line 685:
gcd 401149/s 25% 9% --
</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|#21 "Seattle"}}
 
===Iterative===
<lang perl6>sub gcd (Int $a is copy, Int $b is copy) {
$a & $b == 0 and fail;
($a, $b) = ($b, $a % $b) while $b;
return abs $a;
}</lang>
 
===Recursive===
<lang perl6>multi gcd (0, 0) { fail }
multi gcd (Int $a, 0) { abs $a }
multi gcd (Int $a, Int $b) { gcd $b, $a % $b }</lang>
 
=={{header|Pop11}}==
845

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.