aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-19 17:17:12 +0100
committerGitHub <noreply@github.com>2021-04-19 17:17:12 +0100
commit2fd28e78b216a15c02e486b249f1e909d895f82b (patch)
tree1cf22c16ffd03aa39057138ac74ce4b23cc43244
parent6061cca3b056c3145e29acbbe23c7e946a8f4bd5 (diff)
parent5ddac62498ed8048ef40ddbb63ac144ca91fcb10 (diff)
downloadperlweeklychallenge-club-2fd28e78b216a15c02e486b249f1e909d895f82b.tar.gz
perlweeklychallenge-club-2fd28e78b216a15c02e486b249f1e909d895f82b.tar.bz2
perlweeklychallenge-club-2fd28e78b216a15c02e486b249f1e909d895f82b.zip
Merge pull request #3919 from andemark/branch-for-challenge-109
Challenge 109 Solutions (Raku)
-rw-r--r--challenge-109/mark-anderson/raku/ch-1.raku18
-rw-r--r--challenge-109/mark-anderson/raku/ch-2.raku29
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-109/mark-anderson/raku/ch-1.raku b/challenge-109/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..a063ed088f
--- /dev/null
+++ b/challenge-109/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/env raku
+
+say (1..20).map(&chowla).join(", ");
+
+sub chowla($n)
+{
+ .unique.sum given gather
+ {
+ for 2..$n.sqrt -> $i
+ {
+ if $n %% $i
+ {
+ take $i;
+ take $n div $i;
+ }
+ }
+ }
+}
diff --git a/challenge-109/mark-anderson/raku/ch-2.raku b/challenge-109/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..0dd3ac59c1
--- /dev/null
+++ b/challenge-109/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,29 @@
+#!/usr/bin/env raku
+
+say four-squares(1..7)[4];
+
+sub four-squares(@input)
+{
+ my @chars = "a".."g";
+
+ gather
+ {
+ for @input.permutations -> @perm
+ {
+ my $m = Map.new(@chars Z=> @perm);
+ my ($a, $b, $c, $d, $e, $f, $g) = @perm;
+
+ if $a + $b == $b + $c + $d == $d + $e + $f == $f + $g
+ {
+ take chomp qq:to/END/;
+ @chars.map({ "$_ = $m{$_}" }).join("\n")
+
+ Box 1: a + b = $a + $b = { $a + $b }
+ Box 2: b + c + d = $b + $c + $d = { $b + $c + $d }
+ Box 3: d + e + f = $d + $e + $f = { $d + $e + $f }
+ Box 4: f + g = $f + $g = { $f + $g }
+ END
+ }
+ }
+ }
+}