Here is the pseudocode expressed literally in Perl 6, using the modern (modulo) approach. Note that the subtraction approach might prove useful in the quest to make it shorter.
The rules are to assume the structure provided and just write code for the body, as marked between the comments. You can either put the result in $a or have it be the last value for implicit return.sub gcd ($a is copy, $b is copy -> Int) { # start of golf course while $b != 0 { my $t = $b; $b = $a % $b; $a = $t } # end of golf course option 1 return $a # end, option 2 }
The parameters are not typed, so you can use strange things (not just Ints) if you want during the process, and the result is automatically converted to Int because the return is typed.
I wonder what cool Perl 6 features can be brought to bear, or what tools from the Functional Programming arsinal can be wielded? Feel free to exhibit these for their own sake, even if not a short golf.
In reply to Euclidean algorithm Golf in Perl 6 by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |