aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-02-02 20:52:09 +0000
committerGitHub <noreply@github.com>2025-02-02 20:52:09 +0000
commit59751b5632e4b78d99139c719dc1e80e395a0332 (patch)
tree98bb4330c83c9607caaa54402cac1b74bfdcd083
parent70dc1ed761457730f9a0d8352efec3c9a6c6cb8a (diff)
parentecf2bdd1f0de19e83f06e98ea9a468beb87f07f4 (diff)
downloadperlweeklychallenge-club-59751b5632e4b78d99139c719dc1e80e395a0332.tar.gz
perlweeklychallenge-club-59751b5632e4b78d99139c719dc1e80e395a0332.tar.bz2
perlweeklychallenge-club-59751b5632e4b78d99139c719dc1e80e395a0332.zip
Merge pull request #11518 from BarrOff/barroff-306
feat: add solution for challenge 306 from BarrOff
-rw-r--r--challenge-306/barroff/raku/ch-1.p638
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-306/barroff/raku/ch-1.p6 b/challenge-306/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..06adba164c
--- /dev/null
+++ b/challenge-306/barroff/raku/ch-1.p6
@@ -0,0 +1,38 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub sum-n-slices(@ints, Int $n --> Int) {
+ sum(
+ map(
+ {
+ @ints[$_ - 1] ×
+ min($n, $_, @ints.elems + 1 - $_, @ints.elems + 1 - $n)
+ },
+ 1..@ints.elems
+ )
+ )
+}
+
+sub odd-sum(@ints --> Int) {
+ sum(
+ map(
+ { $_ %% 2 ?? 0 !! sum-n-slices(@ints, $_) },
+ 1..@ints.elems
+ )
+ )
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 2;
+
+ is odd-sum([2, 5, 3, 6, 4]), 77, 'works for [2, 5, 3, 6, 4]';
+ is odd-sum([1, 3]), 4, 'works for [1, 3]';
+}
+
+#| Take user provided number like 1 0 1
+multi sub MAIN(*@ints) {
+ say odd-sum(@ints);
+}