diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-08-30 18:30:23 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-08-30 18:30:23 -0400 |
| commit | 01393c9cc49ab24020c3901afbb27be7b13fe9a7 (patch) | |
| tree | 79cb358d904d53ca02daa0d8ebb1001ac5db746e | |
| parent | c778b5d4e001fd074f4f0e2cf3ca0ed873e17afe (diff) | |
| download | perlweeklychallenge-club-01393c9cc49ab24020c3901afbb27be7b13fe9a7.tar.gz perlweeklychallenge-club-01393c9cc49ab24020c3901afbb27be7b13fe9a7.tar.bz2 perlweeklychallenge-club-01393c9cc49ab24020c3901afbb27be7b13fe9a7.zip | |
1st commit on 128_perl
| -rwxr-xr-x | challenge-128/stuart-little/perl/ch-1.pl | 21 | ||||
| -rwxr-xr-x | challenge-128/stuart-little/perl/ch-2.pl | 18 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-128/stuart-little/perl/ch-1.pl b/challenge-128/stuart-little/perl/ch-1.pl new file mode 100755 index 0000000000..1dfe73a6de --- /dev/null +++ b/challenge-128/stuart-little/perl/ch-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +use warnings; +use v5.12; + +# run <script> <space-separated binary words, with one word representing each row> + +use List::Util qw(reduce); +use List::UtilsBy qw(max_by); + +my ($rows,$cols)=(0,0); +my $digs = length $ARGV[0]; +for my $i (0..scalar @ARGV-1) { + for my $j ($i..scalar @ARGV-1) { + my $max = max_by { length $_ } split /[^0]+/, reduce { sprintf("%0${digs}b", oct("0b$a") | oct("0b$b")) } @ARGV[$i..$j]; + if (($j-$i+1) * (length $max) > $rows * $cols) { + ($rows,$cols) = ($j-$i+1, length $max); + } + } +} + +say join "\n", ('0' x $cols) x $rows; diff --git a/challenge-128/stuart-little/perl/ch-2.pl b/challenge-128/stuart-little/perl/ch-2.pl new file mode 100755 index 0000000000..ccae73e31b --- /dev/null +++ b/challenge-128/stuart-little/perl/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +use warnings; +use v5.12; + +# run <script> <starting arrivals followed by departures, all space-separated> + +use List::Util qw(sum0 zip); + +my @times = sort {$a->[0] cmp $b->[0]} map { [$_->[0], $_->[1] % int((scalar @ARGV)/2)] } zip \@ARGV, [0..scalar @ARGV-1]; +my $sol=0; +my @station = (0) x int((scalar @ARGV)/2); + +for (@times) { + $station[$_->[1]]^=1; + ((sum0 @station) > $sol) && do {$sol = sum0 @station}; +} + +say $sol; |
