diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-05-16 11:04:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-16 11:04:31 +0100 |
| commit | 968faa735a554978650df9c44e46e8f3b0aa88dc (patch) | |
| tree | 78b37a6fc71145bce688dfaea19005f97922d204 | |
| parent | f526ea3ed759332c9b32699353056f3a6a10fa03 (diff) | |
| parent | 6b19f0528782475e6b131c2fcdd8c55542092b4b (diff) | |
| download | perlweeklychallenge-club-968faa735a554978650df9c44e46e8f3b0aa88dc.tar.gz perlweeklychallenge-club-968faa735a554978650df9c44e46e8f3b0aa88dc.tar.bz2 perlweeklychallenge-club-968faa735a554978650df9c44e46e8f3b0aa88dc.zip | |
Merge pull request #10105 from wambash/challenge-week-269
solutions week 269
| -rw-r--r-- | challenge-269/wambash/raku/ch-1.raku | 21 | ||||
| -rw-r--r-- | challenge-269/wambash/raku/ch-2.raku | 30 |
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 +} |
