diff options
| author | holli-holzer <holli.holzer@googlemail.com> | 2019-10-28 19:24:45 +0100 |
|---|---|---|
| committer | holli-holzer <holli.holzer@googlemail.com> | 2019-10-28 19:46:59 +0100 |
| commit | ddc3f01b4574cc77300e6efae902e76bab6b1f59 (patch) | |
| tree | 9e9e641f248e6d980704a7aa30ebc3c0e7398bc7 /challenge-032/markus-holzer | |
| parent | 4ea534b8afcaa524e258936ac5eae51eaa5a2cc9 (diff) | |
| download | perlweeklychallenge-club-ddc3f01b4574cc77300e6efae902e76bab6b1f59.tar.gz perlweeklychallenge-club-ddc3f01b4574cc77300e6efae902e76bab6b1f59.tar.bz2 perlweeklychallenge-club-ddc3f01b4574cc77300e6efae902e76bab6b1f59.zip | |
2 in 1 Solution Markus Holzer
Diffstat (limited to 'challenge-032/markus-holzer')
| -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..0941012c55 --- /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..bb3179d47e --- /dev/null +++ b/challenge-032/markus-holzer/perl6/simpsons.txt @@ -0,0 +1,10 @@ +Marge +Homer +Bart +Maggie +Homer +Bart +Homer +Marge +Homer +Bart
\ 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 |
