aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-184/lubos-kolouch/perl/ch-1.pl31
-rw-r--r--challenge-184/lubos-kolouch/perl/ch-2.pl42
-rw-r--r--challenge-184/lubos-kolouch/python/ch-1.py20
-rw-r--r--challenge-184/lubos-kolouch/python/ch-2.py43
4 files changed, 136 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;
diff --git a/challenge-184/lubos-kolouch/python/ch-1.py b/challenge-184/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..6308218106
--- /dev/null
+++ b/challenge-184/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,20 @@
+""" Challenge 184 Task 1"""
+
+
+def replace_chars(my_input: list) -> list:
+ """Do the exercise"""
+
+ output = []
+
+ for pos, item in enumerate(my_input):
+
+ # assuming to rotate the sequence if more than 100 words
+ next_item = f"{pos % 100:02d}"
+
+ output.append(next_item + item[2:])
+
+ return output
+
+
+assert replace_chars(["ab1234", "cd5678", "ef1342"]) == ["001234", "015678", "021342"]
+assert replace_chars(["pq1122", "rs3334"]) == ["001122", "013334"]
diff --git a/challenge-184/lubos-kolouch/python/ch-2.py b/challenge-184/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..dd601098b5
--- /dev/null
+++ b/challenge-184/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,43 @@
+""" Challenge 184 Task 2"""
+import re
+
+
+def split_array(my_input: list) -> list:
+ """Do the task"""
+
+ list09 = []
+ listaz = []
+
+ for item in my_input:
+
+ temp09 = []
+ tempaz = []
+
+ for char in item:
+
+ if re.match(r"\d", char):
+ temp09.append(int(char))
+
+ if re.match(r"[a-z]", char):
+ tempaz.append(char)
+
+ # ignore if there is some other garbage
+
+ if temp09:
+ list09.append(temp09)
+
+ if tempaz:
+ listaz.append(tempaz)
+
+ return [list09, listaz]
+
+
+assert split_array(["a 1 2 b 0", "3 c 4 d"]) == [
+ [[1, 2, 0], [3, 4]],
+ [["a", "b"], ["c", "d"]],
+]
+
+assert split_array(["1 2", "p q r", "s 3", "4 5 t"]) == [
+ [[1, 2], [3], [4, 5]],
+ [["p", "q", "r"], ["s"], ["t"]],
+]