aboutsummaryrefslogtreecommitdiff
path: root/challenge-163
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-05-06 23:24:23 +0100
committerGitHub <noreply@github.com>2022-05-06 23:24:23 +0100
commita51c066bb310d10a7bf5bd2141e232fa2be22a4a (patch)
tree6e217630c9c2c9a479ee3f2399faeeae05f30fee /challenge-163
parent5384d2ea06a6e038abf645323d621f01890bd412 (diff)
parent83defa93a4f13f3bdd72cf8d4a345797e6a9f107 (diff)
downloadperlweeklychallenge-club-a51c066bb310d10a7bf5bd2141e232fa2be22a4a.tar.gz
perlweeklychallenge-club-a51c066bb310d10a7bf5bd2141e232fa2be22a4a.tar.bz2
perlweeklychallenge-club-a51c066bb310d10a7bf5bd2141e232fa2be22a4a.zip
Merge pull request #6054 from andemark/branch-for-challenge-163
Challenge 163 Solutions (Raku)
Diffstat (limited to 'challenge-163')
-rw-r--r--challenge-163/mark-anderson/raku/ch-1.raku15
-rw-r--r--challenge-163/mark-anderson/raku/ch-2.raku13
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-163/mark-anderson/raku/ch-1.raku b/challenge-163/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..047bbc50a5
--- /dev/null
+++ b/challenge-163/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,15 @@
+#!/usr/bin/env raku
+
+use Test;
+
+is bitwise-sum(1, 2, 3), 3;
+is bitwise-sum(2, 3, 4), 2;
+
+# This is how I'm interpreting 'unique pairs'
+# ((2 & 2) + (2 & 3) + (2 & 4) + (3 & 3) + (3 & 4) + (4 & 4)) == 11
+is bitwise-sum(2, 2, 2, 3, 3, 3, 4, 4, 4), 11;
+
+sub bitwise-sum(+@n)
+{
+ @n.combinations(2).unique(:with(&[eqv])).map({.head +& .tail}).sum
+}
diff --git a/challenge-163/mark-anderson/raku/ch-2.raku b/challenge-163/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..bf22fe3e01
--- /dev/null
+++ b/challenge-163/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+
+use Test;
+
+is summations(1, 2, 3, 4, 5), 42;
+is summations(1, 3, 5, 7, 9), 70;
+is summations(1 .. 20) , 6564120420;
+
+sub summations(+@n)
+{
+ @n = [\+] @n.skip while @n > 1;
+ @n
+}