diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2022-09-26 08:28:44 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2022-09-26 08:28:44 +0000 |
| commit | 9cd795fbe89cbf1801e40200f752696a00d6ea01 (patch) | |
| tree | e7d7aaeb6c0c8a637b1b421ecfe434d318063a82 | |
| parent | ed8b454a791ccbcd0b85ed0bd353680da5cdaee6 (diff) | |
| download | perlweeklychallenge-club-9cd795fbe89cbf1801e40200f752696a00d6ea01.tar.gz perlweeklychallenge-club-9cd795fbe89cbf1801e40200f752696a00d6ea01.tar.bz2 perlweeklychallenge-club-9cd795fbe89cbf1801e40200f752696a00d6ea01.zip | |
w184 - Task 1 & 2
| -rwxr-xr-x | challenge-184/perlboy1967/perl/ch-1.pl | 37 | ||||
| -rwxr-xr-x | challenge-184/perlboy1967/perl/ch-2.pl | 45 |
2 files changed, 82 insertions, 0 deletions
diff --git a/challenge-184/perlboy1967/perl/ch-1.pl b/challenge-184/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..a7b3462ea9 --- /dev/null +++ b/challenge-184/perlboy1967/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 184 + - https://theweeklychallenge.org/blog/perl-weekly-challenge-184/#TASK1 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Sequence Number +Submitted by: Mohammad S Anwar + +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. + +=cut + +use v5.16; +use warnings; + +use Test::More; +use Test::Deep qw(cmp_deeply); + + +sub seqNr (@) { + my ($i,@s) = (0,@_); + map { s/^..(.*)/sprintf("%02d$1",$i++)/re; } @s; +} + + +cmp_deeply([seqNr(qw(ab1234 cd5678 ef1342))],[qw(001234 015678 021342)]); +cmp_deeply([seqNr(qw(pq1122 rs3334))],[qw(001122 013334)]); + +done_testing; diff --git a/challenge-184/perlboy1967/perl/ch-2.pl b/challenge-184/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..5e5ed4fd79 --- /dev/null +++ b/challenge-184/perlboy1967/perl/ch-2.pl @@ -0,0 +1,45 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 184 + - https://theweeklychallenge.org/blog/perl-weekly-challenge-184/#TASK2 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Split Array +Submitted by: Mohammad S Anwar + +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. + +=cut + +use v5.16; +use warnings; + +use Test::More; +use Test::Deep qw(cmp_deeply); + + +sub splitArray (@) { + my ($n,$a); + + for (@_) { + my @s = split(/\s+/); + push(@$n,[grep /[0-9]/,@s]); + push(@$a,[grep /[a-z]/,@s]); + } + + [[grep {@$_} @$n], [grep {@$_} @$a]]; +} + + +cmp_deeply(splitArray('a 1 2 b 0','3 c 4 d'), + [ [[1,2,0],[3,4]], [['a','b'],['c','d']] ]); +cmp_deeply(splitArray('1 2','p q r','s 3','4 5 t'), + [ [[1,2],[3],[4,5]], [['p','q','r'],['s'],['t']] ]); + +done_testing; |
