aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-343/e-choroba/perl/ch-1.pl18
-rwxr-xr-xchallenge-343/e-choroba/perl/ch-2.pl52
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-343/e-choroba/perl/ch-1.pl b/challenge-343/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..ea6e3a6536
--- /dev/null
+++ b/challenge-343/e-choroba/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub zero_friend(@nums) {
+ my $zf = abs shift @nums;
+ abs $_ < $zf and $zf = abs for @nums;
+ return $zf
+}
+
+use Test::More tests => 5;
+
+is zero_friend(4, 2, -1, 3, -2), 1, 'Example 1';
+is zero_friend(-5, 5, -3, 3, -1, 1), 1, 'Example 2';
+is zero_friend(7, -3, 0, 2, -8), 0, 'Example 3';
+is zero_friend(-2, -5, -1, -8), 1, 'Example 4';
+is zero_friend(-2, 2, -4, 4, -1, 1), 1, 'Example 5';
diff --git a/challenge-343/e-choroba/perl/ch-2.pl b/challenge-343/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..8d1681722d
--- /dev/null
+++ b/challenge-343/e-choroba/perl/ch-2.pl
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub champion_team(@grid) {
+ my $max = 0;
+ my %wins;
+ for my $y (0 .. $#grid) {
+ for my $x (0 .. $#{ $grid[$y] }) {
+ my $w = $grid[$y][$x] ? $y : $x;
+ $max = $w if ++$wins{$w} > $wins{$max};
+ }
+ }
+ return "Team $max"
+}
+
+use Test::More tests => 5;
+
+is champion_team(
+ [0, 1, 1],
+ [0, 0, 1],
+ [0, 0, 0],
+ ), 'Team 0', 'Example 1';
+
+is champion_team(
+ [0, 1, 0, 0],
+ [0, 0, 0, 0],
+ [1, 1, 0, 0],
+ [1, 1, 1, 0],
+ ), 'Team 3', 'Example 2';
+
+is champion_team(
+ [0, 1, 0, 1],
+ [0, 0, 1, 1],
+ [1, 0, 0, 0],
+ [0, 0, 1, 0],
+ ), 'Team 0', 'Example 3';
+
+is champion_team(
+ [0, 1, 1],
+ [0, 0, 0],
+ [0, 1, 0],
+ ), 'Team 0', 'Example 4';
+
+is champion_team(
+ [0, 0, 0, 0, 0],
+ [1, 0, 0, 0, 0],
+ [1, 1, 0, 1, 1],
+ [1, 1, 0, 0, 0],
+ [1, 1, 0, 1, 0],
+ ), 'Team 2', 'Example 5';