diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-10-28 21:39:04 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-28 21:39:04 +0000 |
| commit | e6d3c9c9c6bc257fd231db72ba96c3695363c2eb (patch) | |
| tree | 20b8b9352368ba32ffcc5147dd737c6a929bc5bd | |
| parent | 0fd7ce4b2b3450ccfdfb5e8bb2e804577c4d7a31 (diff) | |
| parent | 9884299e456c78a89fa3b5d465d4568e2b2fb456 (diff) | |
| download | perlweeklychallenge-club-e6d3c9c9c6bc257fd231db72ba96c3695363c2eb.tar.gz perlweeklychallenge-club-e6d3c9c9c6bc257fd231db72ba96c3695363c2eb.tar.bz2 perlweeklychallenge-club-e6d3c9c9c6bc257fd231db72ba96c3695363c2eb.zip | |
Merge pull request #864 from holli-holzer/master
2 in 1 Solution 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..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 |
