aboutsummaryrefslogtreecommitdiff
path: root/challenge-075/mathmauney/perl/ch-2.pl
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-075/mathmauney/perl/ch-2.pl')
-rw-r--r--challenge-075/mathmauney/perl/ch-2.pl36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-075/mathmauney/perl/ch-2.pl b/challenge-075/mathmauney/perl/ch-2.pl
new file mode 100644
index 0000000000..1f2c8cfe78
--- /dev/null
+++ b/challenge-075/mathmauney/perl/ch-2.pl
@@ -0,0 +1,36 @@
+#Tries to solve https://perlweeklychallenge.org/blog/perl-weekly-challenge-075/ as perl coding practice.
+
+use strict;
+use warnings;
+use feature qw(say);
+use utf8;
+use Getopt::Long;
+use List::Util qw(sum first max min);
+use Data::Dumper;
+
+my @hist;
+
+GetOptions("histogram=i{1,}", \@hist);
+
+my $count = 1;
+my $max = 0;
+
+while (max(@hist) > 0) {
+ my @positives = map {$_ > 0} @hist;
+ my $l = 0;
+ my $maxl =0;
+ foreach (@positives) {
+ if ($_) {
+ ++$l;
+ } else {
+ $maxl = $l if $l > $maxl;
+ $l = 0;
+ }
+ }
+ $maxl = $l if $l > $maxl;
+ my $rect = $maxl * $count;
+ $max = $rect if $rect > $max;
+ @hist = map {$_ - 1} @hist;
+ ++$count
+}
+say $max;