diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-11-03 14:26:45 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-11-03 14:26:45 +0000 |
| commit | b9f5bb88a4dc66e00946af30e95d9c189cdb954f (patch) | |
| tree | a2ab15eae82ee11130d41c296c8048733f349231 /challenge-032 | |
| parent | 56af77973a0661afd96671e07fa2859448b5ce64 (diff) | |
| download | perlweeklychallenge-club-b9f5bb88a4dc66e00946af30e95d9c189cdb954f.tar.gz perlweeklychallenge-club-b9f5bb88a4dc66e00946af30e95d9c189cdb954f.tar.bz2 perlweeklychallenge-club-b9f5bb88a4dc66e00946af30e95d9c189cdb954f.zip | |
- Added solutions by Adam Russell.
Diffstat (limited to 'challenge-032')
| -rw-r--r-- | challenge-032/adam-russell/perl6/ch-1.p6 | 16 | ||||
| -rw-r--r-- | challenge-032/adam-russell/perl6/ch-2.p6 | 19 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-032/adam-russell/perl6/ch-1.p6 b/challenge-032/adam-russell/perl6/ch-1.p6 new file mode 100644 index 0000000000..e69661271c --- /dev/null +++ b/challenge-032/adam-russell/perl6/ch-1.p6 @@ -0,0 +1,16 @@ +## +# Create a script that either reads standard input +# or one or more files specified on the command-line. +# Count the number of times and then print a summary, +# sorted by the count of each entry. +## +sub MAIN{ + my %word_counts; + for $*IN.lines -> $line { + $line.chomp; + %word_counts{$line}+=1; + } + for %word_counts.sort(*.value).reverse -> $pair { + say $pair.key ~ "\t" ~ $pair.value; + } +} diff --git a/challenge-032/adam-russell/perl6/ch-2.p6 b/challenge-032/adam-russell/perl6/ch-2.p6 new file mode 100644 index 0000000000..6c7c17bcfc --- /dev/null +++ b/challenge-032/adam-russell/perl6/ch-2.p6 @@ -0,0 +1,19 @@ +use JSON::Fast; +## +# Write a function that takes a hashref where the keys +# are labels and the values are integer or floating +# point values. Generate a bar graph of the data and +# display it to stdout. +## +sub term:<MAX-LENGTH> { 10 }; + +sub MAIN($input) { + my %data = from-json $input; + my @sorted = %data.sort(*.value); + my $min = @sorted[0].value; + my $max = @sorted[@sorted.end].value; + for %data.sort(*.value).reverse -> $pair { + print $pair.key ~ "\t| "; + say "#" x ($pair.value - $min + 1) / ($max - $min) * MAX-LENGTH; + } +} |
