diff options
| author | WmMonty <montgomery.west@gmail.com> | 2020-08-15 11:56:30 -0700 |
|---|---|---|
| committer | WmMonty <montgomery.west@gmail.com> | 2020-08-15 11:56:30 -0700 |
| commit | d8769ce3ed43dbdca5a41b3c17a7d27284be2cef (patch) | |
| tree | 1479ae0188117c91b43a5734cf1e9b298bd2a4b7 | |
| parent | 0ad03cbd6337534fa1adf75335be08daafb8298f (diff) | |
| download | perlweeklychallenge-club-d8769ce3ed43dbdca5a41b3c17a7d27284be2cef.tar.gz perlweeklychallenge-club-d8769ce3ed43dbdca5a41b3c17a7d27284be2cef.tar.bz2 perlweeklychallenge-club-d8769ce3ed43dbdca5a41b3c17a7d27284be2cef.zip | |
Git is a weird beast.
| -rwxr-xr-x | challenge-073/will-west/perl/73.1.pl | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/challenge-073/will-west/perl/73.1.pl b/challenge-073/will-west/perl/73.1.pl new file mode 100755 index 0000000000..28790bdc66 --- /dev/null +++ b/challenge-073/will-west/perl/73.1.pl @@ -0,0 +1,63 @@ +#!/usr/bin/perl +use 5.28.1; +use Data::Dumper; +use warnings; +use List::Util qw/min/; + +# Perl Weekly Challange 73 part 1! + +# take an array. +# take a window of size N. +# slide the window down the array + # pick the smallest value in the window each iteration + +my %TEST; + +say join ",", &theSmallestValue(fromEachWindow(ofAnArray())); +testify (\%TEST); #just testing + +sub theSmallestValue{ + my @smallest; + push @smallest, min @$_ for @_; + $TEST{theSmallestValue} = \@smallest; + @smallest +} +sub fromEachWindow{ + my $window = 3; #change to input if wanted + my @windows = slideMap(\@_, $window); + $TEST{fromEachWindow}=\@windows; + @windows +} +sub ofAnArray{ +# asking for input's too tedious, and I don't feel like messing with files. + my @array = map{int rand 20} 1..10; + $TEST{ofAnArray}=\@array; + @array +} + +# UTILITIES (things that don't fit into the flow of the program) +sub slideMap{ + my($aref, #can be anything + $span #window size + )=@_; + + $span = 1 unless $span; + my $adjSpan = $span - 1; #beware off by one + map{[@$aref[$_-$adjSpan..$_]]}$adjSpan..$#$aref +} + + +sub testify{ +#nothing but us tests! +# I mean, if I ever bothered to learn how to use the ACTUAL testing routines . . . + + my $t = pop; + my %test=%$t; + + for (0..$#{$test{fromEachWindow}}){ + my $set = $test{fromEachWindow}[$_]; + my $smol = $test{theSmallestValue}[$_]; + say "smallest number from @$set is $smol"; + } + +} |
