aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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