diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-09-26 16:19:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-26 16:19:19 +0100 |
| commit | 549169504576645a8689e6e4120593d2203525ad (patch) | |
| tree | 5e5368cacf5696b15ce45bfd9c9b7b432a8d4814 | |
| parent | 0f20e7049c9e46e8f07407ba7535e990c5b587d2 (diff) | |
| parent | aa42132b77429b5596533dc77d03bd2bad84781d (diff) | |
| download | perlweeklychallenge-club-549169504576645a8689e6e4120593d2203525ad.tar.gz perlweeklychallenge-club-549169504576645a8689e6e4120593d2203525ad.tar.bz2 perlweeklychallenge-club-549169504576645a8689e6e4120593d2203525ad.zip | |
Merge pull request #6802 from massa/massa/challenge184
It seems to work :-)
| -rw-r--r-- | challenge-184/massa/raku/ch-1.raku | 34 | ||||
| -rw-r--r-- | challenge-184/massa/raku/ch-2.raku | 34 |
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-184/massa/raku/ch-1.raku b/challenge-184/massa/raku/ch-1.raku new file mode 100644 index 0000000000..c856158e35 --- /dev/null +++ b/challenge-184/massa/raku/ch-1.raku @@ -0,0 +1,34 @@ +#!/usr/bin/env raku + +=begin head1 + +Week 184: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-184 + +Task #1: Sequence Number + + You are given list of strings in the format aa9999 i.e. first 2 + characters can be anything 'a-z' followed by 4 digits '0-9'. + + Write a script to replace the first two characters with sequence + starting with '00', '01', '02' etc. + +=end head1 + +use v6; +use Test; + +is-deeply sequence-number('ab1234', 'cd5678', 'ef1342'), + ('001234', '015678', '021342'), 'Example 1'; + +is-deeply sequence-number('pq1122', 'rs3334'), + ('001122', '013334'), 'Example 2'; + +done-testing; + +sub sequence-number(+@list) { + my $seq = 0; + @list.map: { S/ ^ <:L>**2 /{ sprintf '%02d', $seq++ }/ } +} + diff --git a/challenge-184/massa/raku/ch-2.raku b/challenge-184/massa/raku/ch-2.raku new file mode 100644 index 0000000000..9b4576789b --- /dev/null +++ b/challenge-184/massa/raku/ch-2.raku @@ -0,0 +1,34 @@ +#!/usr/bin/env raku + +=begin head1 + +Week 184: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-184 + +Task #2: Split Array + + You are given list of strings containing 0-9 and a-z separated by + space only. + + Write a script to split the data into two arrays, one for integers + and one for alphabets only. + +=end head1 + +use v6; +use Test; + +is-deeply split-array('a 1 2 b 0', '3 c 4 d'), + ( [[1,2,0], [3,4]], [['a','b'], ['c','d']] ), + 'Example 1'; + +is-deeply split-array('1 2', 'p q r', 's 3', '4 5 t'), + ( [[1,2], [3], [4,5]], [['p','q','r'], ['s'], ['t']] ), + 'Example 2'; + +done-testing; + +sub split-array(+@list) { + .map({.{0} or Empty})».map(+ *)».Array.Array, .map({.{1} or Empty}).Array with [ @list.map: { .split(/\s+/).categorize({+ !m/\d/}) } ] +} |
