diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-08-10 11:42:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-10 11:42:22 +0100 |
| commit | 0f7d3874b2845f42f180f0ca107a0d8464708d09 (patch) | |
| tree | d4193b76d45bb08ccbedc1ebabcf1842d8b487ea | |
| parent | 3e25f647466bee33308d2c60b32df5c379a8e0d7 (diff) | |
| parent | 30001a3fb91cc2381e512d797432ba183323241d (diff) | |
| download | perlweeklychallenge-club-0f7d3874b2845f42f180f0ca107a0d8464708d09.tar.gz perlweeklychallenge-club-0f7d3874b2845f42f180f0ca107a0d8464708d09.tar.bz2 perlweeklychallenge-club-0f7d3874b2845f42f180f0ca107a0d8464708d09.zip | |
Merge pull request #2060 from Firedrake/rogerbw-challenge-073
Solutions for challenge #73.
| -rwxr-xr-x | challenge-073/roger-bell-west/perl/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-073/roger-bell-west/perl/ch-2.pl | 35 | ||||
| -rwxr-xr-x | challenge-073/roger-bell-west/raku/ch-1.p6 | 18 | ||||
| -rwxr-xr-x | challenge-073/roger-bell-west/raku/ch-2.p6 | 32 |
4 files changed, 107 insertions, 0 deletions
diff --git a/challenge-073/roger-bell-west/perl/ch-1.pl b/challenge-073/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..9163b0b930 --- /dev/null +++ b/challenge-073/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,22 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use List::Util qw(min); +use Test::More tests => 1; + +is_deeply(msw([1,5,0,2,9,3,7,6,4,8],3), + [0,0,0,2,3,3,4,4], + 'example', + ); + +sub msw { + my $a=shift; + my $s=shift; + my @out; + foreach my $i (0..(scalar @{$a})-$s) { + push @out,min(@{$a}[$i..$i+$s-1]); + } + return \@out; +} diff --git a/challenge-073/roger-bell-west/perl/ch-2.pl b/challenge-073/roger-bell-west/perl/ch-2.pl new file mode 100755 index 0000000000..75a004af8f --- /dev/null +++ b/challenge-073/roger-bell-west/perl/ch-2.pl @@ -0,0 +1,35 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use List::Util qw(min); +use Test::More tests => 2; + +is_deeply(sn([7,8,3,12,10]), + [0,7,0,3,3], + 'example 1', + ); +is_deeply(sn([4,6,5]), + [0,4,4], + 'example 2', + ); + +sub sn { + my $a=shift; + my @out=(0); + my $wm; + foreach my $i (1..$#{$a}) { + if (!defined $wm) { + $wm=$a->[$i-1]; + } else { + $wm=min($wm,$a->[$i-1]); + } + if ($wm < $a->[$i]) { + push @out,$wm; + } else { + push @out,0; + } + } + return \@out; +} diff --git a/challenge-073/roger-bell-west/raku/ch-1.p6 b/challenge-073/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..edadb9e930 --- /dev/null +++ b/challenge-073/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,18 @@ +#! /usr/bin/perl6 + +use Test; + +plan 1; + +is-deeply(msw((1,5,0,2,9,3,7,6,4,8),3), + (0,0,0,2,3,3,4,4), + 'example', + ); + +sub msw(@a,$s) { + my @out; + for (0..(@a.elems-$s)) -> $i { + push @out,min(@a[$i..$i+$s-1]); + } + return @out.flat; +} diff --git a/challenge-073/roger-bell-west/raku/ch-2.p6 b/challenge-073/roger-bell-west/raku/ch-2.p6 new file mode 100755 index 0000000000..dc949ff5e3 --- /dev/null +++ b/challenge-073/roger-bell-west/raku/ch-2.p6 @@ -0,0 +1,32 @@ +#! /usr/bin/perl6 + +use Test; + +plan 2; + +is-deeply(sn((7,8,3,12,10)), + (0,7,0,3,3), + 'example 1', + ); +is-deeply(sn((4,6,5)), + (0,4,4), + 'example 2', + ); + +sub sn(@a) { + my @out=(0); + my $wm; + for (1..@a.end) -> $i { + if (!defined $wm) { + $wm=@a[$i-1]; + } else { + $wm=min($wm,@a[$i-1]); + } + if ($wm < @a[$i]) { + push @out,$wm; + } else { + push @out,0; + } + } + return @out.flat; +} |
