From 12aa1d033ed19a3e3019cf9f6f30b033b5baa1df Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Sun, 30 Aug 2020 14:25:52 +0200 Subject: 075-2 a more idiomatic Raku solution --- challenge-075/ash/blog3.txt | 1 + challenge-075/ash/raku/ch-2a.raku | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 challenge-075/ash/blog3.txt create mode 100644 challenge-075/ash/raku/ch-2a.raku diff --git a/challenge-075/ash/blog3.txt b/challenge-075/ash/blog3.txt new file mode 100644 index 0000000000..0c8d84672d --- /dev/null +++ b/challenge-075/ash/blog3.txt @@ -0,0 +1 @@ +https://andrewshitov.com/2020/08/30/a-more-idiomatic-raku-solution/ diff --git a/challenge-075/ash/raku/ch-2a.raku b/challenge-075/ash/raku/ch-2a.raku new file mode 100644 index 0000000000..edcaf9c16d --- /dev/null +++ b/challenge-075/ash/raku/ch-2a.raku @@ -0,0 +1,21 @@ +#!/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; +for (^@hist).combinations(2) -> ($x, $y) { + $max = max($max, min(@hist[$x .. $y]) * ($y - $x + 1)); +} + +say "The area of a biggest rectangle is $max."; + +# Output: +# +# $ raku ch-2a.raku +# The area of a biggest rectangle is 15. \ No newline at end of file -- cgit