diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-05-20 20:26:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-20 20:26:24 +0100 |
| commit | 998fb0f3e8bfa868783f58cc6846a91b3e502258 (patch) | |
| tree | da2a9a323bc30487e311fba0074a078941637fd0 | |
| parent | 219fb218a706009bfb3452ba4318286d8e0f4545 (diff) | |
| parent | 0cc108ca05071c8923afa2ab41825dd36ebe45aa (diff) | |
| download | perlweeklychallenge-club-998fb0f3e8bfa868783f58cc6846a91b3e502258.tar.gz perlweeklychallenge-club-998fb0f3e8bfa868783f58cc6846a91b3e502258.tar.bz2 perlweeklychallenge-club-998fb0f3e8bfa868783f58cc6846a91b3e502258.zip | |
Merge pull request #8105 from polettix/polettix/pwc217
Add polettix's solution to challenge-217
| -rw-r--r-- | challenge-217/polettix/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-217/polettix/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-217/polettix/perl/ch-1.pl | 21 | ||||
| -rw-r--r-- | challenge-217/polettix/perl/ch-2.pl | 2 | ||||
| -rw-r--r-- | challenge-217/polettix/raku/ch-1.raku | 20 | ||||
| -rw-r--r-- | challenge-217/polettix/raku/ch-2.raku | 2 |
6 files changed, 47 insertions, 0 deletions
diff --git a/challenge-217/polettix/blog.txt b/challenge-217/polettix/blog.txt new file mode 100644 index 0000000000..e2064fa36a --- /dev/null +++ b/challenge-217/polettix/blog.txt @@ -0,0 +1 @@ +https://etoobusy.polettix.it/2023/05/18/pwc217-sorted-matrix/ diff --git a/challenge-217/polettix/blog1.txt b/challenge-217/polettix/blog1.txt new file mode 100644 index 0000000000..ca9b400916 --- /dev/null +++ b/challenge-217/polettix/blog1.txt @@ -0,0 +1 @@ +https://etoobusy.polettix.it/2023/05/19/pwc217-max-number/ diff --git a/challenge-217/polettix/perl/ch-1.pl b/challenge-217/polettix/perl/ch-1.pl new file mode 100644 index 0000000000..96cd802876 --- /dev/null +++ b/challenge-217/polettix/perl/ch-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +use v5.24; +use warnings; + +my @matrix = map { [ split m{\s*,\s*}mxs ] } @ARGV; +say third_smallest(@matrix); + +sub third_smallest { + my @three_smallest; + for my $row (@_) { + for my $item ($row->@*) { + my $idx = scalar(@three_smallest); + --$idx while $idx > 0 && $three_smallest[$idx - 1] > $item; + next if $idx > 2; + splice(@three_smallest, $idx, 0, $item); + pop(@three_smallest) while @three_smallest > 3; + + } + } + return $three_smallest[-1]; +} diff --git a/challenge-217/polettix/perl/ch-2.pl b/challenge-217/polettix/perl/ch-2.pl new file mode 100644 index 0000000000..81e71dcbad --- /dev/null +++ b/challenge-217/polettix/perl/ch-2.pl @@ -0,0 +1,2 @@ +#!/usr/bin/env perl +print join('', sort { ($b . $a) <=> ($a . $b) } @ARGV), "\n"; diff --git a/challenge-217/polettix/raku/ch-1.raku b/challenge-217/polettix/raku/ch-1.raku new file mode 100644 index 0000000000..b96f565abe --- /dev/null +++ b/challenge-217/polettix/raku/ch-1.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku +use v6; +sub MAIN (*@rows) { + my @matrix = @rows.map({ [ .split(/ \s* \, \s* /)ยป.Int ] }); + put third-smallest(@matrix); +} + +sub third-smallest (@matrix) { + my @three-smallest; + for @matrix -> $row { + for @$row -> $item { + my $idx = @three-smallest.elems; + --$idx while $idx > 0 && @three-smallest[$idx - 1] > $item; + next if $idx > 2; + @three-smallest.splice($idx, 0, $item); + @three-smallest.pop while @three-smallest > 3; + } + } + return @three-smallest[*-1]; +} diff --git a/challenge-217/polettix/raku/ch-2.raku b/challenge-217/polettix/raku/ch-2.raku new file mode 100644 index 0000000000..2b34c40492 --- /dev/null +++ b/challenge-217/polettix/raku/ch-2.raku @@ -0,0 +1,2 @@ +#!/usr/bin/env raku +@*ARGS.sort({"$^b$^a".Int <=> "$^a$^b".Int}).join('').put; |
