aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-180/lubos-kolouch/perl/ch-1.pl34
-rw-r--r--challenge-180/lubos-kolouch/perl/ch-2.pl17
-rw-r--r--challenge-180/lubos-kolouch/python/ch-1.py20
-rw-r--r--challenge-180/lubos-kolouch/python/ch-2.py11
4 files changed, 82 insertions, 0 deletions
diff --git a/challenge-180/lubos-kolouch/perl/ch-1.pl b/challenge-180/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..53e9a246b2
--- /dev/null
+++ b/challenge-180/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,34 @@
+package main;
+use strict;
+use warnings;
+
+sub first_unique_char {
+ my $what = shift;
+ my %seen_chars;
+
+ my $pos = 0;
+
+ while ( $pos < length($what) ) {
+ my $char = substr( $what, $pos, 1 );
+ return $char
+ if ( index( $what, $char, $pos + 1 ) == -1 )
+ and ( not exists( $seen_chars{$char} ) );
+
+ # This is needed for the case LL, otherwise it would not detect the second L
+ $seen_chars{$char} = 1;
+ $pos++;
+ }
+ return '';
+}
+
+use Test::More;
+
+is( first_unique_char("Perl Weekly Challenge"), "P" );
+
+is( first_unique_char("Long Live Perl"), "o" );
+
+is( first_unique_char("LL"), "" );
+
+done_testing;
+
+1;
diff --git a/challenge-180/lubos-kolouch/perl/ch-2.pl b/challenge-180/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..1758292f89
--- /dev/null
+++ b/challenge-180/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,17 @@
+package main;
+use strict;
+use warnings;
+use Data::Dumper;
+
+sub trim_list {
+ my ( $what, $i ) = @_;
+
+ return grep { $_ > $i } @$what;
+}
+
+use Test::More;
+
+is( trim_list( [ 1, 2, 3, 4, 5 ], 3 ), 2 );
+is( trim_list( [ 9, 0, 6, 2, 3, 8, 5 ], 4 ), 4 );
+done_testing;
+1;
diff --git a/challenge-180/lubos-kolouch/python/ch-1.py b/challenge-180/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..1430711571
--- /dev/null
+++ b/challenge-180/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,20 @@
+""" Challenge 180 Task 1 LK Python """
+from collections import Counter
+
+
+def first_unique_char(what: str) -> str:
+ """Return the first unique character"""
+
+ chars_counter = Counter(what)
+ for char in what:
+ if chars_counter[char] == 1:
+ return char
+
+ return ""
+
+
+assert first_unique_char("Perl Weekly Challenge") == "P"
+
+assert first_unique_char("Long Live Perl") == "o"
+
+assert first_unique_char("LL") == ""
diff --git a/challenge-180/lubos-kolouch/python/ch-2.py b/challenge-180/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..820764d9e3
--- /dev/null
+++ b/challenge-180/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,11 @@
+""" Challenge 180 Task 2 LK Python """
+
+
+def trim_list(what: list, i: int) -> list:
+ """Return the trimmed list"""
+
+ return [elem for elem in what if elem > i]
+
+
+assert trim_list([1, 2, 3, 4, 5], 3) == [4, 5]
+assert trim_list([9, 0, 6, 2, 3, 8, 5], 4) == [9, 6, 8, 5]