From ceb82af7db5446b9a6e85296d7abc8550924c7c9 Mon Sep 17 00:00:00 2001 From: Torgny Lyon Date: Mon, 30 Sep 2024 20:14:45 +0200 Subject: Add solutions for week 289 --- challenge-289/torgny-lyon/blog.txt | 1 + challenge-289/torgny-lyon/perl/ch-1.pl | 16 ++++++++++++++++ challenge-289/torgny-lyon/perl/ch-2.pl | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 challenge-289/torgny-lyon/blog.txt create mode 100755 challenge-289/torgny-lyon/perl/ch-1.pl create mode 100755 challenge-289/torgny-lyon/perl/ch-2.pl diff --git a/challenge-289/torgny-lyon/blog.txt b/challenge-289/torgny-lyon/blog.txt new file mode 100644 index 0000000000..dfa8f90929 --- /dev/null +++ b/challenge-289/torgny-lyon/blog.txt @@ -0,0 +1 @@ +https://www.abc.se/~torgny/pwc.html#289 diff --git a/challenge-289/torgny-lyon/perl/ch-1.pl b/challenge-289/torgny-lyon/perl/ch-1.pl new file mode 100755 index 0000000000..8b36455377 --- /dev/null +++ b/challenge-289/torgny-lyon/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use v5.40; + +use Test::More tests => 3; + +use List::Util qw(uniq); + +sub get_third_maximum { + my @l = uniq sort { $b <=> $a } @_; + return @l > 2 ? $l[2] : $l[0]; +} + +is(get_third_maximum(5, 6, 4, 1), 4); +is(get_third_maximum(4, 5), 5); +is(get_third_maximum(1, 2, 2, 3), 1); diff --git a/challenge-289/torgny-lyon/perl/ch-2.pl b/challenge-289/torgny-lyon/perl/ch-2.pl new file mode 100755 index 0000000000..633e165850 --- /dev/null +++ b/challenge-289/torgny-lyon/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use v5.40; + +use List::Util qw(shuffle); + +my $s = <