diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-02-19 20:56:24 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-19 20:56:24 +0000 |
| commit | 4cb80ee66440819fcdb966c92cf6a3350e43c75e (patch) | |
| tree | c1b417bc26ca5e188047bfa9279f8854a8cf9fa5 | |
| parent | d710e9926733e8aaa4c5a4b664549300363a14ba (diff) | |
| parent | a4e198589fa5a8acd8986f4f8820e3fc5b10c87b (diff) | |
| download | perlweeklychallenge-club-4cb80ee66440819fcdb966c92cf6a3350e43c75e.tar.gz perlweeklychallenge-club-4cb80ee66440819fcdb966c92cf6a3350e43c75e.tar.bz2 perlweeklychallenge-club-4cb80ee66440819fcdb966c92cf6a3350e43c75e.zip | |
Merge pull request #7593 from wambash/challenge-week-204
solutions week 204
| -rw-r--r-- | challenge-204/wambash/raku/ch-1.raku | 16 | ||||
| -rw-r--r-- | challenge-204/wambash/raku/ch-2.raku | 28 |
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-204/wambash/raku/ch-1.raku b/challenge-204/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..13322bd090 --- /dev/null +++ b/challenge-204/wambash/raku/ch-1.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku +subset Monotonic where { [≥] |$_ or [≤] |$_ }; + +multi monotonic-array ( +@a ) { @a ~~ Monotonic } + +multi MAIN (Bool :test($)!) { + use Test; + is monotonic-array(1,2,2,3), True; + is monotonic-array(1,3,2), False; + is monotonic-array(6,5,5,4), True; + done-testing; +} + +multi MAIN (+@nums) { + say +monotonic-array @nums +} diff --git a/challenge-204/wambash/raku/ch-2.raku b/challenge-204/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..44d34ad833 --- /dev/null +++ b/challenge-204/wambash/raku/ch-2.raku @@ -0,0 +1,28 @@ +#!/usr/bin/env raku + +sub reshape-matrix (+@matrix, :$c!,:$r!) { + CATCH { default { warn $_ } } + @matrix[*;*] + andthen .batch($c) + andthen Array.new: $_, :shape($r;$c)\ + andthen .[$r-1;$c-1] ?? $_ !! Nil +} + +multi MAIN (Bool :test($)!) { + use Test; + CONTROL { + default { + like $_, /:s out of range/; + .resume + } + } + is-deeply reshape-matrix([ [ 1, 2 ], [ 3, 4 ] ]):1r:4c, Array.new: [[ 1, 2, 3, 4 ],], :shape(1,4); + is-deeply reshape-matrix([ 1, 2, 3 ] , [ 4, 5, 6 ]):3r:2c, Array.new: [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], :shape(3,2); + is-deeply reshape-matrix([ [ 1, 2 ], ]):3r:2c, Nil; + is-deeply reshape-matrix([ [ 1, 2 ], ]):1r:1c, Nil; + done-testing; +} + +multi MAIN (*@matrix, UInt :$r!, UInt :$c!) { + say reshape-matrix(@matrix):$r:$c // 0 +} |
