aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-24 07:55:07 +0100
committerGitHub <noreply@github.com>2020-09-24 07:55:07 +0100
commit9f91492ea571cc5c7fe2a1e592d0ea1e18f482de (patch)
treecb1925c1e8f4aaff6c4229359ffcb4a6dfe56ead
parent42351f25505f13304a6a211914d5547a828c2a83 (diff)
parent5c75ba06822ed08cc222f73636fe7bc72eef5fa3 (diff)
downloadperlweeklychallenge-club-9f91492ea571cc5c7fe2a1e592d0ea1e18f482de.tar.gz
perlweeklychallenge-club-9f91492ea571cc5c7fe2a1e592d0ea1e18f482de.tar.bz2
perlweeklychallenge-club-9f91492ea571cc5c7fe2a1e592d0ea1e18f482de.zip
Merge pull request #2361 from holli-holzer/master
now with histogram
-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