aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2023-07-10 18:37:40 +0200
committerLubos Kolouch <lubos@kolouch.net>2023-07-10 18:37:40 +0200
commitdf8e942514dd66e8eab4d1a4946140b58a57f996 (patch)
treef4fbed45b7e0c90c77ac3efd2f7fe28cb01bc779
parent80e57ec8f3de321e2f66184490f16b335a281896 (diff)
downloadperlweeklychallenge-club-df8e942514dd66e8eab4d1a4946140b58a57f996.tar.gz
perlweeklychallenge-club-df8e942514dd66e8eab4d1a4946140b58a57f996.tar.bz2
perlweeklychallenge-club-df8e942514dd66e8eab4d1a4946140b58a57f996.zip
feat(challenge-225/lubos-kolouch/perl,python/): Challenge 225 LK Perl Python
-rw-r--r--challenge-225/lubos-kolouch/perl/ch-1.pl24
-rw-r--r--challenge-225/lubos-kolouch/perl/ch-2.pl23
-rw-r--r--challenge-225/lubos-kolouch/python/ch-1.py16
-rw-r--r--challenge-225/lubos-kolouch/python/ch-2.py19
4 files changed, 82 insertions, 0 deletions
diff --git a/challenge-225/lubos-kolouch/perl/ch-1.pl b/challenge-225/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..99803d2ae3
--- /dev/null
+++ b/challenge-225/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+sub max_words {
+ my @list = @_;
+ my $max_count = 0;
+
+ foreach my $sentence (@list) {
+ my $word_count = scalar( split( /\s+/, $sentence ) );
+ $max_count = $word_count if $word_count > $max_count;
+ }
+
+ return $max_count;
+}
+
+# testing
+my @list = (
+ "Perl and Raku belong to the same family.",
+ "I love Perl.",
+ "The Perl and Raku Conference."
+);
+
+print max_words(@list), "\n"; # should print 8
diff --git a/challenge-225/lubos-kolouch/perl/ch-2.pl b/challenge-225/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..6a8219b87f
--- /dev/null
+++ b/challenge-225/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+use List::Util qw(sum);
+
+sub left_right_sum_diff {
+ my @ints = @_;
+ my @left = map { $_ > 0 ? sum( @ints[ 0 .. $_ - 1 ] ) : 0 } ( 0 .. $#ints );
+ my @right = map { $_ < $#ints ? sum( @ints[ $_ + 1 .. $#ints ] ) : 0 }
+ ( 0 .. $#ints );
+ return [ map { abs( $left[$_] - $right[$_] ) } ( 0 .. $#ints ) ];
+}
+
+# testing
+my @ints = ( 10, 4, 8, 3 );
+print join( ", ", @{ left_right_sum_diff(@ints) } ),
+ "\n"; # should print "15, 1, 11, 22"
+
+@ints = (1);
+print join( ", ", @{ left_right_sum_diff(@ints) } ), "\n"; # should print "0"
+
+@ints = ( 1, 2, 3, 4, 5 );
+print join( ", ", @{ left_right_sum_diff(@ints) } ),
+ "\n"; # should print "14, 11, 6, 1, 10"
diff --git a/challenge-225/lubos-kolouch/python/ch-1.py b/challenge-225/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..6826ff1a30
--- /dev/null
+++ b/challenge-225/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def max_words(lst):
+ return max(len(sentence.split()) for sentence in lst)
+
+
+# testing
+list = [
+ "Perl and Raku belong to the same family.",
+ "I love Perl.",
+ "The Perl and Raku Conference.",
+]
+
+print(max_words(list)) # should print 8
diff --git a/challenge-225/lubos-kolouch/python/ch-2.py b/challenge-225/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..18ed09f29b
--- /dev/null
+++ b/challenge-225/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def left_right_sum_diff(ints):
+ left = [sum(ints[:i]) for i in range(len(ints))]
+ right = [sum(ints[i + 1 :]) for i in range(len(ints))]
+ return [abs(l - r) for l, r in zip(left, right)]
+
+
+# testing
+ints = [10, 4, 8, 3]
+print(left_right_sum_diff(ints)) # should print [15, 1, 11, 22]
+
+ints = [1]
+print(left_right_sum_diff(ints)) # should print [0]
+
+ints = [1, 2, 3, 4, 5]
+print(left_right_sum_diff(ints)) # should print [14, 11, 6, 1, 10]