aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-04-05 16:23:07 +0100
committerGitHub <noreply@github.com>2022-04-05 16:23:07 +0100
commit3f6ebe8fe9b68efb18a96187f36b6a75471219d0 (patch)
tree39b4e70c88c20415508fae4681c225fd84fcff23
parent9b0a005eb498e5d2a8e49ff0ba45dce16a82f389 (diff)
parent9e5cdd4d0bfc4bc54550cf8d49267342b2144e39 (diff)
downloadperlweeklychallenge-club-3f6ebe8fe9b68efb18a96187f36b6a75471219d0.tar.gz
perlweeklychallenge-club-3f6ebe8fe9b68efb18a96187f36b6a75471219d0.tar.bz2
perlweeklychallenge-club-3f6ebe8fe9b68efb18a96187f36b6a75471219d0.zip
Merge pull request #5887 from 2colours/branch-for-challenge-159
Week #159 solutions (2colours)
-rwxr-xr-xchallenge-159/2colours/raku/ch-1.raku9
-rwxr-xr-xchallenge-159/2colours/raku/ch-2.raku15
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)}";