aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2022-02-17 19:03:53 +0100
committerLubos Kolouch <lubos@kolouch.net>2022-02-17 19:03:53 +0100
commit6a933e40878b068e5b069f94c3ae685f3d8769b7 (patch)
tree5a48ca39cda774a0257927bf847aa8b837c42a8c
parentcecb0a9230ee9b7152b708e5a9fa5a676c9735e5 (diff)
downloadperlweeklychallenge-club-6a933e40878b068e5b069f94c3ae685f3d8769b7.tar.gz
perlweeklychallenge-club-6a933e40878b068e5b069f94c3ae685f3d8769b7.tar.bz2
perlweeklychallenge-club-6a933e40878b068e5b069f94c3ae685f3d8769b7.zip
Challenge 152 Task 1 LK Perl Python PHP
-rw-r--r--challenge-152/lubos-kolouch/perl/ch-1.pl26
-rw-r--r--challenge-152/lubos-kolouch/php/ch-1.php20
-rw-r--r--challenge-152/lubos-kolouch/python/ch-1.py22
3 files changed, 68 insertions, 0 deletions
diff --git a/challenge-152/lubos-kolouch/perl/ch-1.pl b/challenge-152/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..be4e9ea03b
--- /dev/null
+++ b/challenge-152/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+use List::Util qw/min/;
+
+sub get_min_count {
+ my @in_arr = @_;
+
+ my $min_sum = 0;
+
+ for my $sub_arr (@in_arr) {
+
+ # so obviously it is not a tree, just independent arrays
+ # so I can just take a min from each row
+
+ $min_sum += min(@$sub_arr);
+ }
+
+ return $min_sum;
+}
+
+use Test::More;
+
+is( get_min_count( [1], [ 5, 3 ], [ 2, 3, 4 ], [ 7, 1, 0, 2 ], [ 6, 4, 5, 2, 8 ] ), 8 );
+is( get_min_count( [5], [ 2, 3 ], [ 4, 1, 5 ], [ 0, 1, 2, 3 ], [ 7, 2, 4, 1, 9 ] ), 9 );
+
+done_testing;
diff --git a/challenge-152/lubos-kolouch/php/ch-1.php b/challenge-152/lubos-kolouch/php/ch-1.php
new file mode 100644
index 0000000000..f8e66e2224
--- /dev/null
+++ b/challenge-152/lubos-kolouch/php/ch-1.php
@@ -0,0 +1,20 @@
+<?php
+
+function get_min_count($in_arr) {
+
+ $min_sum = 0;
+
+ foreach ($in_arr as $sub_arr) {
+
+ # so obviously it is not a tree, just independent arrays
+ # so I can just take a min from each row
+
+ $min_sum += min($sub_arr);
+ }
+
+ return $min_sum;
+}
+
+get_min_count([ [1], [ 5, 3 ], [ 2, 3, 4 ], [ 7, 1, 0, 2 ], [ 6, 4, 5, 2, 8 ] ]) == 8 or throw new Exception("Test1 failed");
+get_min_count([ [5], [ 2, 3 ], [ 4, 1, 5 ], [ 0, 1, 2, 3 ], [ 7, 2, 4, 1, 9 ] ]) == 9 or throw new Exception("Test2 failed");
+?>
diff --git a/challenge-152/lubos-kolouch/python/ch-1.py b/challenge-152/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..6e170349ca
--- /dev/null
+++ b/challenge-152/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,22 @@
+""" Challenge 152 Task 1 """
+
+
+def get_min_count(in_arr: list):
+ """ Find out the lists minimum """
+
+ min_sum = 0
+
+ for sub_arr in in_arr:
+
+ # so obviously it is not a tree, just independent arrays
+ # so I can just take a min from each row
+
+ min_sum += min(sub_arr)
+
+ return min_sum
+
+
+assert get_min_count([[1], [5, 3], [2, 3, 4], [7, 1, 0, 2], [6, 4, 5, 2,
+ 8]]) == 8
+assert get_min_count([[5], [2, 3], [4, 1, 5], [0, 1, 2, 3], [7, 2, 4, 1,
+ 9]]) == 9