diff options
| -rw-r--r-- | challenge-184/bruce-gray/raku/ch-1.raku | 22 | ||||
| -rw-r--r-- | challenge-184/bruce-gray/raku/ch-2.raku | 24 |
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-184/bruce-gray/raku/ch-1.raku b/challenge-184/bruce-gray/raku/ch-1.raku new file mode 100644 index 0000000000..3698d5265f --- /dev/null +++ b/challenge-184/bruce-gray/raku/ch-1.raku @@ -0,0 +1,22 @@ +sub task1 ( @a ) { + my $seq = '00'; + return @a.map: { + / ^ <[a..z]> ** 2 ( <[0..9]> ** 4 ) $ / or die; + $seq++ ~ $0; + } +} +# I could have used .subst, but then I could not detect bad input: +# return @a.map: *.subst( / ^ <[a..z]> ** 2 ( <[0..9]> ** 4 ) $ /, { $seq++ ~ $0 } ); +# If I used `ยป.subst`, I would not need `.map`, but the sequences could be out of order. + +use Test; +my @tests = + ( <ab1234 cd5678 ef1342>, + <001234 015678 021342> ), + ( <pq1122 rs3334>, + <001122 013334> ), +; +plan +@tests; +for @tests -> ( $in, $expected ) { + is task1($in), $expected; +} diff --git a/challenge-184/bruce-gray/raku/ch-2.raku b/challenge-184/bruce-gray/raku/ch-2.raku new file mode 100644 index 0000000000..39e3deb10a --- /dev/null +++ b/challenge-184/bruce-gray/raku/ch-2.raku @@ -0,0 +1,24 @@ +sub task2 ( @list ) { + my ( @nums, @alphas ); + for @list { + my %h = .words.classify({ ?/<alpha>/ }); + push @alphas, $_ with %h{True}; + push @nums , $_ with %h{False}; + } + return @nums, @alphas; +} + + +use Test; +my @tests = + ( ( 'a 1 2 b 0', '3 c 4 d' ), + ( [ ['1','2','0'], ['3','4'] ], [ ['a','b'], ['c','d'] ] ) ), + + ( ( '1 2', 'p q r', 's 3', '4 5 t' ), + ( [ ['1','2'], ['3'], ['4','5'] ], [ [ 'p', 'q', 'r' ], ['s'], ['t'] ] ) ), +; + +plan +@tests; +for @tests -> ( $in, $expected ) { + is-deeply $expected, task2($in); +} |
