diff options
| author | 冯昶 <seaker@qq.com> | 2020-08-31 17:55:06 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2020-08-31 17:55:06 +0800 |
| commit | fcd02aeeda87c122867e4173ad34ac8e4c752aa2 (patch) | |
| tree | 2c91adbb6c158528d06c1294e066bd34f4c9eae3 /challenge-075/ash/raku/ch-2.raku | |
| parent | 4a2d3428b9c5d6fbbfabafe0d9303b45bdb59295 (diff) | |
| parent | 87c6f1e47af81cce9da9dde6e73ca9de5bd77367 (diff) | |
| download | perlweeklychallenge-club-fcd02aeeda87c122867e4173ad34ac8e4c752aa2.tar.gz perlweeklychallenge-club-fcd02aeeda87c122867e4173ad34ac8e4c752aa2.tar.bz2 perlweeklychallenge-club-fcd02aeeda87c122867e4173ad34ac8e4c752aa2.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-075/ash/raku/ch-2.raku')
| -rw-r--r-- | challenge-075/ash/raku/ch-2.raku | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-075/ash/raku/ch-2.raku b/challenge-075/ash/raku/ch-2.raku new file mode 100644 index 0000000000..7253841f3f --- /dev/null +++ b/challenge-075/ash/raku/ch-2.raku @@ -0,0 +1,44 @@ +#!/usr/bin/env raku + +# Task 2 from +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-075/ + +# Comments: https://andrewshitov.com/2020/08/29/largest-rectangle-histogram-the-raku-challenge-week-75-task-2/ + +# my @hist = 2, 1, 4, 5, 3, 7; +my @hist = 3, 2, 3, 5, 7, 5; + +my $max = 0; +my @max; + +for ^@hist -> $start { + for $start ^..^ @hist -> $end { + my $area = min(@hist[$start .. $end]) * (1 + $end - $start); + # say "$start..$end = $area"; + if $area > $max { + $max = $area; + @max = $start, $end; + } + } +} + +say "The biggest rectangle is between the columns @max[0] and @max[1] and its area is $max."; + +# Output: +# $ raku ch-2.raku +# 0..1 = 4 +# 0..2 = 6 +# 0..3 = 8 +# 0..4 = 10 +# 0..5 = 12 +# 1..2 = 4 +# 1..3 = 6 +# 1..4 = 8 +# 1..5 = 10 +# 2..3 = 6 +# 2..4 = 9 +# 2..5 = 12 +# 3..4 = 10 +# 3..5 = 15 +# 4..5 = 10 +# The biggest rectangle is between the columns 3 and 5 and its area is 15. |
