diff options
| author | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-09-23 20:52:20 +0200 |
|---|---|---|
| committer | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-09-23 20:52:20 +0200 |
| commit | 5c75ba06822ed08cc222f73636fe7bc72eef5fa3 (patch) | |
| tree | 333576295087c5c369d668290d45ac2466989f04 | |
| parent | 4363345dd35aab6d50430cafdcc9e19ca3d9ac6a (diff) | |
| download | perlweeklychallenge-club-5c75ba06822ed08cc222f73636fe7bc72eef5fa3.tar.gz perlweeklychallenge-club-5c75ba06822ed08cc222f73636fe7bc72eef5fa3.tar.bz2 perlweeklychallenge-club-5c75ba06822ed08cc222f73636fe7bc72eef5fa3.zip | |
now with histogram
| -rw-r--r-- | challenge-079/markus-holzer/raku/ch-2.raku | 19 |
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 |
