aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-338/kjetillll/perl/ch-1.pl27
-rw-r--r--challenge-338/kjetillll/perl/ch-2.pl12
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-338/kjetillll/perl/ch-1.pl b/challenge-338/kjetillll/perl/ch-1.pl
new file mode 100644
index 0000000000..a188d7abba
--- /dev/null
+++ b/challenge-338/kjetillll/perl/ch-1.pl
@@ -0,0 +1,27 @@
+use List::Util qw(max sum);
+
+sub f {
+ max map sum( @$_ ), @_
+}
+
+print pop(@$_) == f(@$_) ? "ok\n" : "error\n" for
+
+[ [4, 4, 4, 4],
+ [10, 0, 0, 0],
+ [2, 2, 2, 9] => 16 ],
+
+[ [1, 5],
+ [7, 3],
+ [3, 5] => 10 ],
+
+[ [1, 2, 3],
+ [3, 2, 1] => 6 ],
+
+[ [2, 8, 7],
+ [7, 1, 3],
+ [1, 9, 5] => 17 ],
+
+[ [10, 20, 30],
+ [5, 5, 5],
+ [0, 100, 0],
+ [25, 25, 25] => 100 ];
diff --git a/challenge-338/kjetillll/perl/ch-2.pl b/challenge-338/kjetillll/perl/ch-2.pl
new file mode 100644
index 0000000000..9dde8eca2e
--- /dev/null
+++ b/challenge-338/kjetillll/perl/ch-2.pl
@@ -0,0 +1,12 @@
+use List::Util qw(max);
+
+sub f { my($a1, $a2) = @_; max map { //; map abs( $' - $_ ), @$a2 } @$a1 }
+sub f_less_memory { my($a1, $a2) = @_; max map { //; max map abs( $' - $_ ), @$a2 } @$a1 }
+
+print f( @$_)==$$_[2] ? "ok\n" : "error\n" and
+print f_less_memory(@$_)==$$_[2] ? "ok\n" : "error\n" for
+[ [4, 5, 7], [9, 1, 3, 4] => 6 ],
+[ [2, 3, 5, 4], [3, 2, 5, 5, 8, 7] => 6 ],
+[ [2, 1, 11, 3], [2, 5, 10, 2] => 9 ],
+[ [1, 2, 3], [3, 2, 1] => 2 ],
+[ [1, 0, 2, 3], [5, 0] => 5 ],