aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2022-10-01 19:21:28 +0200
committerLubos Kolouch <lubos@kolouch.net>2022-10-01 19:21:28 +0200
commitb505fe32ab56d20d7c40913a2748cd1692fc633e (patch)
tree690b51f47b7954c67df625d18358ee1e36b9f0d3
parentfaaee55b3039755a4ec54ef1a86c310523f19b16 (diff)
downloadperlweeklychallenge-club-b505fe32ab56d20d7c40913a2748cd1692fc633e.tar.gz
perlweeklychallenge-club-b505fe32ab56d20d7c40913a2748cd1692fc633e.tar.bz2
perlweeklychallenge-club-b505fe32ab56d20d7c40913a2748cd1692fc633e.zip
feat(challenge-184/lubos-kolouch/perl/ch-{1,2}.pl): Challenge 184 LK Perl Task 1 2
-rw-r--r--challenge-184/lubos-kolouch/perl/ch-1.pl31
-rw-r--r--challenge-184/lubos-kolouch/perl/ch-2.pl42
2 files changed, 73 insertions, 0 deletions
diff --git a/challenge-184/lubos-kolouch/perl/ch-1.pl b/challenge-184/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..390cddeb73
--- /dev/null
+++ b/challenge-184/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,31 @@
+package main;
+use strict;
+use warnings;
+
+sub replace_chars {
+ my @input = @_;
+
+ my @output;
+ my $pos = 0;
+
+ for my $item (@input) {
+
+ # assuming to rotate the sequence if more than 100 words
+ my $next_item = sprintf( "%.2d", $pos % 100 );
+
+ push @output, $next_item . substr( $item, 2 );
+ $pos++;
+
+ }
+
+ return \@output;
+}
+
+use Test::More;
+
+is_deeply( replace_chars( ( 'ab1234', 'cd5678', 'ef1342' ) ),
+ [ '001234', '015678', '021342' ] );
+is_deeply( replace_chars( ( 'pq1122', 'rs3334' ) ), [ '001122', '013334' ] );
+
+done_testing;
+1;
diff --git a/challenge-184/lubos-kolouch/perl/ch-2.pl b/challenge-184/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..4ecb68a793
--- /dev/null
+++ b/challenge-184/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,42 @@
+package main;
+use strict;
+use warnings;
+
+sub split_array {
+ my @input = @_;
+
+ my @list09;
+ my @listaz;
+
+ for my $item (@input) {
+
+ my @temp09;
+ my @tempaz;
+
+ for my $char ( split / /, $item ) {
+
+ push @temp09, $char if $char =~ /\d/;
+ push @tempaz, $char if $char =~ /[a-z]/;
+
+ # ignore if there is some other garbage
+ }
+
+ push @list09, \@temp09 if @temp09;
+ push @listaz, \@tempaz if @tempaz;
+ }
+ return [ @list09, @listaz ];
+}
+
+use Test::More;
+
+is_deeply(
+ split_array( ( 'a 1 2 b 0', '3 c 4 d' ) ),
+ [ [ 1, 2, 0 ], [ 3, 4 ], [ 'a', 'b' ], [ 'c', 'd' ] ]
+);
+is_deeply(
+ split_array( ( '1 2', 'p q r', 's 3', '4 5 t' ) ),
+ [ [ 1, 2 ], [3], [ 4, 5 ], [ 'p', 'q', 'r' ], ['s'], ['t'] ]
+);
+
+done_testing;
+1;