aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-12-31 23:44:13 +0000
committerGitHub <noreply@github.com>2023-12-31 23:44:13 +0000
commitf1372ee79592a7221bafcb068556f270303cdeac (patch)
tree789fb2caf511b2ba7d83babedbc235864024cf59
parent8f580b1c13f8e5ccea389cfb7f73903ceb5a9293 (diff)
parent60e4cea94781ebeb96b0ea3bbf6dee0969f8dc5b (diff)
downloadperlweeklychallenge-club-f1372ee79592a7221bafcb068556f270303cdeac.tar.gz
perlweeklychallenge-club-f1372ee79592a7221bafcb068556f270303cdeac.tar.bz2
perlweeklychallenge-club-f1372ee79592a7221bafcb068556f270303cdeac.zip
Merge pull request #9322 from wambash/challenge-week-249
Challenge week 249
-rw-r--r--challenge-249/wambash/raku/ch-1.raku18
-rw-r--r--challenge-249/wambash/raku/ch-2.raku36
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-249/wambash/raku/ch-1.raku b/challenge-249/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..3ed6fe7bda
--- /dev/null
+++ b/challenge-249/wambash/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/env raku
+
+sub equal-pairs (+ints) {
+ my %bints := ints.Bag;
+
+ %bints.kxxv.batch(2) if %bints.values.all %% 2
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ cmp-ok equal-pairs(3,2,3,2,2,2).sort, &[~~], ((2,2),(2,2),(3,3));
+ is-deeply equal-pairs(1,2,3,4), Empty;
+ done-testing;
+}
+
+multi MAIN (+ints) {
+ say equal-pairs ints
+}
diff --git a/challenge-249/wambash/raku/ch-2.raku b/challenge-249/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..27e20c49d2
--- /dev/null
+++ b/challenge-249/wambash/raku/ch-2.raku
@@ -0,0 +1,36 @@
+#!/usr/bin/env raku
+
+enum DI <I D>;
+
+multi DI-reducer ( @a, I, :&f=&take) {
+ f @a.head;
+ @a.skip
+}
+
+multi DI-reducer ( @a, D, :&f=&take) {
+ f @a.tail;
+ @a.head: * - 1
+}
+
+sub DI-string-match ($s) {
+ my DI @si = |$s.comb.map( { DI::{$_} } ), I ;
+
+ gather { reduce &DI-reducer, ^@si, |@si }
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply DI-reducer((0,1,2,3), I, :f(&item)), (1,2,3);
+ is-deeply DI-reducer((0,1,2,3), D, :f(&item)), (0,1,2);
+ is-deeply gather { DI-reducer((0,1,2,3), D) }, (3,);
+ is-deeply gather { DI-reducer((2,), I) }, (2,);
+ is-deeply DI-string-match('IDID'), (0,4,1,3,2);
+ is-deeply DI-string-match('III'), (0,1,2,3);
+ is-deeply DI-string-match('DDI'), (3,2,0,1);
+ is-deeply DI-string-match('ID' x 100).head(2), (0,200);
+ done-testing;
+}
+
+multi MAIN ($s) {
+ say DI-string-match $s
+}