aboutsummaryrefslogtreecommitdiff
path: root/challenge-079
diff options
context:
space:
mode:
authorMarkus "Holli" Holzer <holli.holzer@gmail.com>2020-09-23 20:52:20 +0200
committerMarkus "Holli" Holzer <holli.holzer@gmail.com>2020-09-23 20:52:20 +0200
commit5c75ba06822ed08cc222f73636fe7bc72eef5fa3 (patch)
tree333576295087c5c369d668290d45ac2466989f04 /challenge-079
parent4363345dd35aab6d50430cafdcc9e19ca3d9ac6a (diff)
downloadperlweeklychallenge-club-5c75ba06822ed08cc222f73636fe7bc72eef5fa3.tar.gz
perlweeklychallenge-club-5c75ba06822ed08cc222f73636fe7bc72eef5fa3.tar.bz2
perlweeklychallenge-club-5c75ba06822ed08cc222f73636fe7bc72eef5fa3.zip
now with histogram
Diffstat (limited to 'challenge-079')
-rw-r--r--challenge-079/markus-holzer/raku/ch-2.raku19
1 files changed, 18 insertions, 1 deletions
diff --git a/challenge-079/markus-holzer/raku/ch-2.raku b/challenge-079/markus-holzer/raku/ch-2.raku
index d674dca8af..c3a961e708 100644
--- a/challenge-079/markus-holzer/raku/ch-2.raku
+++ b/challenge-079/markus-holzer/raku/ch-2.raku
@@ -1,9 +1,26 @@
unit sub MAIN( *@N where @N.all ~~ Int );
+my $max = @N.max;
+
+my @histo = reverse [Z]
+ (' ', '-', |(1..$max) ),
+ |@N.map: { $_, '-', |('#' xx $_), |(' ' xx ($max - $_)) };
+
+my @pretty = @histo.map({
+ .join('')
+ .subst(/ <?after '#'> ( \s+ ) <?before '#'> /, { '~' x .chars }, :g)
+ .subst('', ' ', :g )});
+
+
+.say and .indices('~').elems.say with @pretty.join("\n");
+
+# This was my first attempt before I realized we're supposed to
+# print the histogram too and I can just count the ~ in the output
+
sub index-find { @N.pairs.grep( *.value >= $^h ).map: *.key }
sub index-diff { ($^i.cache.skip >>->> $^i).map: * - 1 }
-say (@N.max...0)
+say ($max...0)
.map( &index-find )
.map( &index-diff )
.flat