diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-09 22:51:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-09 22:51:10 +0100 |
| commit | 6b6bc6fd97d038027c12b98d2fe2b541d2eb7599 (patch) | |
| tree | e6f3919e2934809fde62285730ece5df40a0c5d9 | |
| parent | 78501a1a799fb0f93e30e70ae0c8e18ea0eaf83c (diff) | |
| parent | eb3dc2e59549db57fa49ce97688355010ac9a584 (diff) | |
| download | perlweeklychallenge-club-6b6bc6fd97d038027c12b98d2fe2b541d2eb7599.tar.gz perlweeklychallenge-club-6b6bc6fd97d038027c12b98d2fe2b541d2eb7599.tar.bz2 perlweeklychallenge-club-6b6bc6fd97d038027c12b98d2fe2b541d2eb7599.zip | |
Merge pull request #10811 from torgnylyon/master
Add solutions for week 286
| -rw-r--r-- | challenge-286/torgny-lyon/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-286/torgny-lyon/perl/ch-1.pl | 8 | ||||
| -rwxr-xr-x | challenge-286/torgny-lyon/perl/ch-2.pl | 22 |
3 files changed, 31 insertions, 0 deletions
diff --git a/challenge-286/torgny-lyon/blog.txt b/challenge-286/torgny-lyon/blog.txt new file mode 100644 index 0000000000..dc04de6771 --- /dev/null +++ b/challenge-286/torgny-lyon/blog.txt @@ -0,0 +1 @@ +https://www.abc.se/~torgny/pwc.html#286 diff --git a/challenge-286/torgny-lyon/perl/ch-1.pl b/challenge-286/torgny-lyon/perl/ch-1.pl new file mode 100755 index 0000000000..63bc588059 --- /dev/null +++ b/challenge-286/torgny-lyon/perl/ch-1.pl @@ -0,0 +1,8 @@ +#!/usr/bin/perl + +use v5.40; + +open my $f, '<', $0; +undef $/; +@_ = split /\s+/, <$f>; +say $_[ int rand @_ ]; diff --git a/challenge-286/torgny-lyon/perl/ch-2.pl b/challenge-286/torgny-lyon/perl/ch-2.pl new file mode 100755 index 0000000000..0044409085 --- /dev/null +++ b/challenge-286/torgny-lyon/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use v5.40; + +use Test::More tests => 3; + +use List::Util qw(min max pairs); + +sub play_game { + return min(@_) if @_ == 2; + my $f = \&max; + return play_game( + map { + $f = $f == \&min ? \&max : \&min; + $f->($_->[0], $_->[1]); + } pairs @_ + ); +} + +is(play_game(2, 1, 4, 5, 6, 3, 0, 2), 1); +is(play_game(0, 5, 3, 2), 0); +is(play_game(9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8), 2); |
