aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHumberto Massa <humbertomassa@gmail.com>2022-09-26 08:53:11 -0300
committerHumberto Massa <humbertomassa@gmail.com>2022-09-26 08:53:11 -0300
commitaa42132b77429b5596533dc77d03bd2bad84781d (patch)
tree29cae596e90e4468d3308a239861ff59e70289f1
parent80947a1d472b184f4b8018aabaccb28300c91bb6 (diff)
downloadperlweeklychallenge-club-aa42132b77429b5596533dc77d03bd2bad84781d.tar.gz
perlweeklychallenge-club-aa42132b77429b5596533dc77d03bd2bad84781d.tar.bz2
perlweeklychallenge-club-aa42132b77429b5596533dc77d03bd2bad84781d.zip
It seems to work :-)
-rw-r--r--challenge-184/massa/raku/ch-1.raku34
-rw-r--r--challenge-184/massa/raku/ch-2.raku34
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/}) } ]
+}