aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-09-03 22:18:00 +0100
committerGitHub <noreply@github.com>2022-09-03 22:18:00 +0100
commit4d6ee5c533134c1c950bc12637661b6c99f734f2 (patch)
tree005800a273c15cdb00ef50575e85b89696696223
parent0ea24ad3f2e62e9531e778ee31b582d73efe4b77 (diff)
parent4c819887545ed63afc468a94c16561099a0e7411 (diff)
downloadperlweeklychallenge-club-4d6ee5c533134c1c950bc12637661b6c99f734f2.tar.gz
perlweeklychallenge-club-4d6ee5c533134c1c950bc12637661b6c99f734f2.tar.bz2
perlweeklychallenge-club-4d6ee5c533134c1c950bc12637661b6c99f734f2.zip
Merge pull request #6687 from LubosKolouch/master
Challenge 180
-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]