diff options
| -rwxr-xr-x | challenge-159/2colours/raku/ch-1.raku | 9 | ||||
| -rwxr-xr-x | challenge-159/2colours/raku/ch-2.raku | 15 |
2 files changed, 24 insertions, 0 deletions
diff --git a/challenge-159/2colours/raku/ch-1.raku b/challenge-159/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..07f037d7f0 --- /dev/null +++ b/challenge-159/2colours/raku/ch-1.raku @@ -0,0 +1,9 @@ +#!/usr/bin/env raku + +sub farey(Int() $n) { + my @rest = (([\,] (1..$n)) ZX/ (1..$n)).flat.unique.sort.map(*.nude.join: '/'); + ('0/1', |@rest) +} + +my $n = prompt 'Input: $n = '; +say "Output: {farey($n).join(', ')}.";
\ No newline at end of file diff --git a/challenge-159/2colours/raku/ch-2.raku b/challenge-159/2colours/raku/ch-2.raku new file mode 100755 index 0000000000..e71d651672 --- /dev/null +++ b/challenge-159/2colours/raku/ch-2.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + +constant \minus-one = -1; + +multi möbius(1 --> 1) {} +multi möbius($n where { .is-prime } --> minus-one) {} +multi möbius($n) { + my $divisor = (2..^$n).first($n %% *); + my $quotient = $n div $divisor; + $quotient %% $divisor ?? 0 !! möbius($divisor) * möbius($quotient) +} + + +my $n = prompt 'Input: $n = '; +say "Output: {möbius($n)}"; |
