aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2024-05-15 23:43:42 +0200
committerJan Krňávek <Jan.Krnavek@gmail.com>2024-05-15 23:43:42 +0200
commit6b19f0528782475e6b131c2fcdd8c55542092b4b (patch)
tree0e149cce15ccecd0ca1dc6d67433a668b7338c43
parent64b8c830c57e76dc96d88d66ead474e829ccb220 (diff)
downloadperlweeklychallenge-club-6b19f0528782475e6b131c2fcdd8c55542092b4b.tar.gz
perlweeklychallenge-club-6b19f0528782475e6b131c2fcdd8c55542092b4b.tar.bz2
perlweeklychallenge-club-6b19f0528782475e6b131c2fcdd8c55542092b4b.zip
solutions week 269
-rw-r--r--challenge-269/wambash/raku/ch-1.raku21
-rw-r--r--challenge-269/wambash/raku/ch-2.raku30
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-269/wambash/raku/ch-1.raku b/challenge-269/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..356a7d7a19
--- /dev/null
+++ b/challenge-269/wambash/raku/ch-1.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+
+sub bitwise-or (+ints) {
+ ints
+ andthen .grep: * %% 2
+ andthen .head: 2
+ andthen .elems == 2
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is bitwise-or(1,2,3,4,5), True;
+ is bitwise-or(2,3,8,16), True;
+ is bitwise-or(1,3 ... 9), False;
+ is bitwise-or(1...10¹⁹), True;
+ done-testing;
+}
+
+multi MAIN (+ints) {
+ say bitwise-or +ints
+}
diff --git a/challenge-269/wambash/raku/ch-2.raku b/challenge-269/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..3a7c66c701
--- /dev/null
+++ b/challenge-269/wambash/raku/ch-2.raku
@@ -0,0 +1,30 @@
+#!/usr/bin/env raku
+
+proto distributive-reducer ((@arr1,@arr2), $int) {*}
+multi distributive-reducer ((@arr1, @arr2), $int where @arr1 ~~ Empty) { ($int,), @arr2 }
+multi distributive-reducer ((@arr1, @arr2), $int where @arr2 ~~ Empty ) { @arr1, ($int,) }
+multi distributive-reducer ((@arr1, @arr2), $int where {@arr1.tail > @arr2.tail} ) { (|@arr1,$int), @arr2 }
+multi distributive-reducer ((@arr1, @arr2), $int ) { @arr1, (|@arr2, $int) }
+
+sub distributive-elements (+ints) {
+ ints
+ andthen ((),()), |ints
+ andthen .reduce: &distributive-reducer
+ andthen |.head,|.skip.head
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply distributive-reducer(((),()),1), ((1,),());
+ is-deeply distributive-reducer(((1,),()),2), ((1,),(2,));
+ is-deeply distributive-reducer(((1,3),(2,)),4), ((1,3,4),(2,));
+ is-deeply distributive-reducer(((1,),(2,)),3), ((1,),(2,3));
+ is distributive-elements(2,1,3,4,5), (2,3,4,5,1);
+ is distributive-elements(3, 2, 4), (3, 4, 2);
+ is distributive-elements(5, 4, 3, 8), (5, 3, 4, 8);
+ done-testing;
+}
+
+multi MAIN (+ints) {
+ put distributive-elements ints
+}