From 95dc39b5367981a433476c079814230baec7cb6a Mon Sep 17 00:00:00 2001 From: Util Date: Sun, 19 Feb 2023 15:58:53 -0600 Subject: Add TWC 204 solutions by Bruce Gray (Raku only). --- challenge-204/bruce-gray/raku/ch-1.raku | 11 +++++++++++ challenge-204/bruce-gray/raku/ch-2.raku | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 challenge-204/bruce-gray/raku/ch-1.raku create mode 100644 challenge-204/bruce-gray/raku/ch-2.raku 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; +} -- cgit