Skip to content

Instantly share code, notes, and snippets.

@bdw
Last active February 19, 2018 10:14
Show Gist options
  • Save bdw/e9b7c6e3e92e788d2fdcec6df6c171ab to your computer and use it in GitHub Desktop.
Save bdw/e9b7c6e3e92e788d2fdcec6df6c171ab to your computer and use it in GitHub Desktop.
euclid-gcd.p6
#!/usr/bin/env perl6
multi sub euclid ($a is copy, $b is copy) {
while ($b != 0) {
($a, $b) = ($b, $a % $b);
}
return $a;
}
multi sub euclid ($a, $b where $a < $b) {
euclid($b, $a)
}
multi sub MAIN(Int:D $a, Int:D $b) {
say "gcd($a,$b) = ", euclid($a, $b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment