diff options
| author | Torgny Lyon <torgny@abc.se> | 2025-09-17 20:28:38 +0200 |
|---|---|---|
| committer | Torgny Lyon <torgny@abc.se> | 2025-09-17 20:28:38 +0200 |
| commit | ea1ffe97b88ea6b4f595b2d3ee4cb76358e8cd79 (patch) | |
| tree | e39ca5726e5885fba8d08752f453326847a7e96c | |
| parent | 55d28e9bcf39421ac381128d84d3a3beaa518a27 (diff) | |
| download | perlweeklychallenge-club-ea1ffe97b88ea6b4f595b2d3ee4cb76358e8cd79.tar.gz perlweeklychallenge-club-ea1ffe97b88ea6b4f595b2d3ee4cb76358e8cd79.tar.bz2 perlweeklychallenge-club-ea1ffe97b88ea6b4f595b2d3ee4cb76358e8cd79.zip | |
Add solutions for week 339
| -rw-r--r-- | challenge-339/torgny-lyon/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-339/torgny-lyon/perl/ch-1.pl | 16 | ||||
| -rwxr-xr-x | challenge-339/torgny-lyon/perl/ch-2.pl | 18 |
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-339/torgny-lyon/blog.txt b/challenge-339/torgny-lyon/blog.txt new file mode 100644 index 0000000000..9828222192 --- /dev/null +++ b/challenge-339/torgny-lyon/blog.txt @@ -0,0 +1 @@ +https://www.abc.se/~torgny/pwc.html#339 diff --git a/challenge-339/torgny-lyon/perl/ch-1.pl b/challenge-339/torgny-lyon/perl/ch-1.pl new file mode 100755 index 0000000000..f63dc898fe --- /dev/null +++ b/challenge-339/torgny-lyon/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use v5.42; + +use Test::More tests => 5; + +sub find_max_diff { + my @ints = sort { $b <=> $a } map { abs } @_; + $ints[0] * $ints[1] - $ints[$#ints] * $ints[$#ints - 1]; +} + +is(find_max_diff(5, 9, 3, 4, 6), 42); +is(find_max_diff(1, -2, 3, -4), 10); +is(find_max_diff(-3, -1, -2, -4), 10); +is(find_max_diff(10, 2, 0, 5, 1), 50); +is(find_max_diff(7, 8, 9, 10, 10), 44); diff --git a/challenge-339/torgny-lyon/perl/ch-2.pl b/challenge-339/torgny-lyon/perl/ch-2.pl new file mode 100755 index 0000000000..ad724c293d --- /dev/null +++ b/challenge-339/torgny-lyon/perl/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +use v5.42; + +use Test::More tests => 5; + +use List::Util qw(max); + +sub find_peak_gain { + my $altitude; + max(0, map { $altitude += $_ } @_); +} + +is(find_peak_gain(-5, 1, 5, -9, 2), 1); +is(find_peak_gain(10, 10, 10, -25), 30); +is(find_peak_gain(3, -4, 2, 5, -6, 1), 6); +is(find_peak_gain(-1, -2, -3, -4), 0); +is(find_peak_gain(-10, 15, 5), 10); |
