aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-07-03 19:01:23 +0100
committerGitHub <noreply@github.com>2022-07-03 19:01:23 +0100
commit4bf3b2b11dc8185ea1c494753f01714900ba7727 (patch)
tree66b61755f608afb577ea14194dd9e7287126bae3
parent79f9659bf28ff1e13fe32ddde5183ff20151b9a7 (diff)
parentb6990dba45b40936533a7a21d8658a0aca9bf817 (diff)
downloadperlweeklychallenge-club-4bf3b2b11dc8185ea1c494753f01714900ba7727.tar.gz
perlweeklychallenge-club-4bf3b2b11dc8185ea1c494753f01714900ba7727.tar.bz2
perlweeklychallenge-club-4bf3b2b11dc8185ea1c494753f01714900ba7727.zip
Merge pull request #6380 from Util/branch-for-challenge-171
Add TWC 171 solutions by Bruce Gray : only Raku.
-rw-r--r--challenge-171/bruce-gray/raku/ch-1.raku11
-rw-r--r--challenge-171/bruce-gray/raku/ch-2.raku21
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-171/bruce-gray/raku/ch-1.raku b/challenge-171/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..e11ecea897
--- /dev/null
+++ b/challenge-171/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,11 @@
+use Prime::Factor;
+
+constant @abundant_odd = grep { .&proper-divisors.sum > $_ }, (1, 3, 5 … Inf);
+
+say @abundant_odd.head(20);
+
+
+
+# https://oeis.org/A005231
+constant @A005231 = 945, 1575, 2205, 2835, 3465, 4095, 4725, 5355, 5775, 5985, 6435, 6615, 6825, 7245, 7425, 7875, 8085, 8415, 8505, 8925, 9135, 9555, 9765, 10395, 11025, 11655, 12285, 12705, 12915, 13545, 14175, 14805, 15015, 15435, 16065, 16695, 17325, 17955;
+warn unless @abundant_odd.head(+@A005231) eqv @A005231.Seq;
diff --git a/challenge-171/bruce-gray/raku/ch-2.raku b/challenge-171/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..dae9ab8216
--- /dev/null
+++ b/challenge-171/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,21 @@
+my &compose := &[∘]; # This single binding is the complete solution to the task.
+
+
+# Testing:
+my &h = compose &ffff, &gggg;
+
+sub ffff ($p) { say "Calculating {&?ROUTINE.name} of $p"; $p * 2 }
+sub gggg ($p) { say "Calculating {&?ROUTINE.name} of $p"; $p / 3 }
+
+say h(15);
+
+# Function composition is already provided by Raku's ∘ infix operator.
+# See: https://docs.raku.org/language/operators#infix_o,_infix_%E2%88%98
+
+# Of interest: The creation of &h can occur *before* the definition of the subs that will compose it.
+
+# TIMTOWTDI; any one of these lines could replace the first line:
+# sub compose ( &f, &g --> Code ) { return &f ∘ &g }
+# my &compose = -> &f, &g { &f ∘ &g };
+# my &compose = { &^f ∘ &^g };
+# my &compose = * ∘ *;