diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2020-11-16 14:08:46 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2020-11-16 14:08:46 -0500 |
| commit | 027c247a80ab6c8a7732437f797d5c7c0c38e708 (patch) | |
| tree | 691192a879740ecba34d821e8863af4ff998a2b1 /challenge-032 | |
| parent | cff21bb0b22502e3b0ef8a4f3946e5f921647115 (diff) | |
| download | perlweeklychallenge-club-027c247a80ab6c8a7732437f797d5c7c0c38e708.tar.gz perlweeklychallenge-club-027c247a80ab6c8a7732437f797d5c7c0c38e708.tar.bz2 perlweeklychallenge-club-027c247a80ab6c8a7732437f797d5c7c0c38e708.zip | |
initial commit on 031,032,048
Diffstat (limited to 'challenge-032')
| -rw-r--r-- | challenge-032/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-032/stuart-little/raku/ch-1.p6 | 22 | ||||
| -rwxr-xr-x | challenge-032/stuart-little/raku/ch-2.p6 | 24 |
3 files changed, 47 insertions, 0 deletions
diff --git a/challenge-032/stuart-little/README b/challenge-032/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-032/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-032/stuart-little/raku/ch-1.p6 b/challenge-032/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..9961930fcd --- /dev/null +++ b/challenge-032/stuart-little/raku/ch-1.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env perl6 +use v6; + +my %*SUB-MAIN-OPTS=:named-anywhere,; +sub MAIN( + Bool :c(:$csv), + *@FILES, + ) { + + sub freq(@a,$cflag) { + my @bg=@a.Bag.sort({$^b.value leg $^a.value}); + (! $cflag) ?? + (@bg) !! + (@bg.map({ $_.key ~ ',' ~ $_.value })) + } + + my @a=(! @FILES) + ?? ($*IN.lines) + !! (@FILES.map({ $_.IO.lines }).flat); + for freq(@a,$csv) {.say}; +} + diff --git a/challenge-032/stuart-little/raku/ch-2.p6 b/challenge-032/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..79743021c9 --- /dev/null +++ b/challenge-032/stuart-little/raku/ch-2.p6 @@ -0,0 +1,24 @@ +#!/usr/bin/env perl6 +use v6; + +my %*SUB-MAIN-OPTS=:named-anywhere,; +sub MAIN( + Str :b(:$by) ="values", + *@ARGS, + ) { + + sub chrt(%h, Str $by) { + %h.sort({ ($by eq "labels") && $_.key + || ($by eq "values") && -$_.value }) + .map({ sprintf("%10s", $_.key) ~ ' | ' ~ '#' x $_.value }) + } + + my %h=@ARGS; + for chrt(%h.map({$_.key => $_.value.Int}).Hash,$by) {.say}; +} + +sub USAGE() { + print Q:c:to/EOH/; + Usage: <script> [hash passed as key value key value ..] [-b|--by=values(default)|labels] +EOH +} |
