diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-02-19 22:44:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-19 22:44:33 +0000 |
| commit | 40442c2606fea02012c84e84e7440dfcd7d52feb (patch) | |
| tree | bae263b9722bf937f960195ff18eae63fdc3cd74 | |
| parent | debbd421fc623a421d07ebafa3a1c291153f829e (diff) | |
| parent | 95dc39b5367981a433476c079814230baec7cb6a (diff) | |
| download | perlweeklychallenge-club-40442c2606fea02012c84e84e7440dfcd7d52feb.tar.gz perlweeklychallenge-club-40442c2606fea02012c84e84e7440dfcd7d52feb.tar.bz2 perlweeklychallenge-club-40442c2606fea02012c84e84e7440dfcd7d52feb.zip | |
Merge pull request #7596 from Util/branch-for-challenge-204
Add TWC 204 solutions by Bruce Gray (Raku only).
| -rw-r--r-- | challenge-204/bruce-gray/raku/ch-1.raku | 11 | ||||
| -rw-r--r-- | challenge-204/bruce-gray/raku/ch-2.raku | 18 |
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-204/bruce-gray/raku/ch-1.raku b/challenge-204/bruce-gray/raku/ch-1.raku new file mode 100644 index 0000000000..be330f8503 --- /dev/null +++ b/challenge-204/bruce-gray/raku/ch-1.raku @@ -0,0 +1,11 @@ +sub task1 ( @ns --> Bool ) { ([<=] @ns) || ([>=] @ns) } + + +my @tests = + (1,2,2,3) => 1, + (1,3,2) => 0, + (6,5,5,4) => 1, +; +use Test; +plan +@tests; +is +task1(.key), .value for @tests; diff --git a/challenge-204/bruce-gray/raku/ch-2.raku b/challenge-204/bruce-gray/raku/ch-2.raku new file mode 100644 index 0000000000..aa8ee3dc80 --- /dev/null +++ b/challenge-204/bruce-gray/raku/ch-2.raku @@ -0,0 +1,18 @@ +sub task2 (@matrix, UInt $r, UInt $c) { + return @matrix.flat.elems == $r * $c + ?? @matrix.flat.batch($c) + !! 0; +} + + +my @tests = + ( 1, 4, ( ( 1, 2 ) , ( 3, 4 ) ) ) => ( ( 1, 2, 3, 4, ), ), + ( 3, 2, ( ( 1, 2, 3 ) , ( 4, 5, 6 ) ) ) => ( ( 1, 2 ), ( 3, 4 ), ( 5, 6 ) ), + ( 3, 2, ( ( 1, 2 ) , ) ) => 0 , +; +use Test; +plan +@tests; +for @tests -> ( :key($in), :value($expected) ) { + my ( $r, $c, $matrix ) = $in.list; + is-deeply task2( $matrix, $r, $c ), $expected; +} |
