diff options
| -rw-r--r-- | challenge-032/markus-holzer/perl6/ch-1-and-2.pl6 | 26 | ||||
| -rw-r--r-- | challenge-032/markus-holzer/perl6/simpsons.txt | 10 | ||||
| -rw-r--r-- | challenge-032/markus-holzer/perl6/test.bat | 6 |
3 files changed, 42 insertions, 0 deletions
diff --git a/challenge-032/markus-holzer/perl6/ch-1-and-2.pl6 b/challenge-032/markus-holzer/perl6/ch-1-and-2.pl6 new file mode 100644 index 0000000000..f1eb4d25dc --- /dev/null +++ b/challenge-032/markus-holzer/perl6/ch-1-and-2.pl6 @@ -0,0 +1,26 @@ +my %*SUB-MAIN-OPTS = :named-anywhere; + +multi sub MAIN( *@files, Bool :$csv, Bool :$graph, Bool :$sort-by-label ) +{ + CATCH { return .message.say } + + my @words = @files + ?? @files.map( |*.IO.lines ) + !! |$*ARGFILES.lines; + + my $weights = Bag.new( @words ); + my $lngst = max $weights.keys.map( *.chars ); + + my $format = $csv ?? "%s, %s" !! + $graph ?? "%{$lngst}s | %s " !! + "%-{$lngst}s %s " ; + + my &sorter = $sort-by-label + ?? { $^a.key cmp $^b.key } + !! { $^b.value <=> $^a.value }; + + .say for $weights + .sort( &sorter ) + .map({ .key => $graph ?? "#" x .value !! .value }) + .map({ sprintf $format, .key, .value }); +}
\ No newline at end of file diff --git a/challenge-032/markus-holzer/perl6/simpsons.txt b/challenge-032/markus-holzer/perl6/simpsons.txt new file mode 100644 index 0000000000..fafebd89f4 --- /dev/null +++ b/challenge-032/markus-holzer/perl6/simpsons.txt @@ -0,0 +1,10 @@ +Bart +Bart +Maggie +Marge +Homer +Bart +Homer +Bart +Marge +Marge
\ No newline at end of file diff --git a/challenge-032/markus-holzer/perl6/test.bat b/challenge-032/markus-holzer/perl6/test.bat new file mode 100644 index 0000000000..8da2aff480 --- /dev/null +++ b/challenge-032/markus-holzer/perl6/test.bat @@ -0,0 +1,6 @@ +@echo off +type simpsons.txt|call perl6 ch-1-and-2.pl6 +type simpsons.txt|call perl6 ch-1-and-2.pl6 --csv +call perl6 ch-1-and-2.pl6 simpsons.txt simpsons.txt +call perl6 ch-1-and-2.pl6 simpsons.txt --graph +call perl6 ch-1-and-2.pl6 --csv simpsons.txt --sort-by-label |
