diff options
23 files changed, 1938 insertions, 1462 deletions
diff --git a/challenge-032/dave-cross/perl5/ch-1.pl b/challenge-032/dave-cross/perl5/ch-1.pl new file mode 100644 index 0000000000..42a706b7ed --- /dev/null +++ b/challenge-032/dave-cross/perl5/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +my $csv; +if ($ARGV[0] eq '-csv') { + shift; + $csv = 1; +} + +my %count; + +while (<>) { + chomp; + $count{$_}++; +} + +for (sort { $count{$b} <=> $count{$a} } keys %count) { + say $_, ($csv ? ',' : "\t"), $count{$_}; +} diff --git a/challenge-032/dave-cross/perl5/ch-2.pl b/challenge-032/dave-cross/perl5/ch-2.pl new file mode 100644 index 0000000000..37fbda8759 --- /dev/null +++ b/challenge-032/dave-cross/perl5/ch-2.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +use List::Util 'max'; +use Term::ReadKey; + +my $input = { + apple => 3, + cherry => 2, + banana => 1, +}; + +say "Sort by keys:"; +say text_bar($input); +say "\nSort by values:"; +say text_bar($input, 'v'); + +sub text_bar { + my ($data) = @_; + + my $sort_by_keys = 1; + if (lc ($_[1] // '') eq 'v') { + $sort_by_keys = 0; + } + + my ($width) = GetTerminalSize; + say $width; + + my $keylen = max map { length } keys %$data; + my $maxval = max values %$data; + + my $step = int($width - $keylen - 3) / $maxval; + + if ($sort_by_keys) { + for (sort keys %$data) { + printf "%${keylen}s : %s\n", $_, '#' x ($data->{$_} * $step); + } + } else{ + for (sort { $data->{$b} <=> $data->{$a} } keys %$data) { + printf "%${keylen}s : %s\n", $_, '#' x ($data->{$_} * $step); + } + } +} diff --git a/challenge-032/dave-cross/perl5/input b/challenge-032/dave-cross/perl5/input new file mode 100644 index 0000000000..00fe021a08 --- /dev/null +++ b/challenge-032/dave-cross/perl5/input @@ -0,0 +1,6 @@ +apple +banana +apple +cherry +cherry +apple diff --git a/challenge-032/simon-proctor/all.csv b/challenge-032/simon-proctor/all.csv new file mode 100644 index 0000000000..a9dc63c1c6 --- /dev/null +++ b/challenge-032/simon-proctor/all.csv @@ -0,0 +1,7 @@ +"apple",29 +"cherry",29 +"strawberry",28 +"lime",24 +"pear",23 +"lemon",22 +"banana",1 diff --git a/challenge-032/simon-proctor/all.txt b/challenge-032/simon-proctor/all.txt new file mode 100644 index 0000000000..1c38af6052 --- /dev/null +++ b/challenge-032/simon-proctor/all.txt @@ -0,0 +1,7 @@ +cherry 29 +apple 29 +strawberry 28 +lime 24 +pear 23 +lemon 22 +banana 1 diff --git a/challenge-032/simon-proctor/large-test.txt b/challenge-032/simon-proctor/large-test.txt new file mode 100644 index 0000000000..996a4625e3 --- /dev/null +++ b/challenge-032/simon-proctor/large-test.txt @@ -0,0 +1,100 @@ +apple +lemon +cherry +apple +cherry +strawberry +pear +cherry +pear +apple +strawberry +strawberry +cherry +lime +lemon +lemon +lemon +pear +cherry +apple +cherry +pear +lemon +pear +strawberry +apple +pear +pear +lime +strawberry +apple +strawberry +cherry +lemon +apple +lime +lemon +apple +apple +lemon +strawberry +strawberry +lime +lime +lime +strawberry +pear +lemon +apple +lemon +lime +pear +strawberry +cherry +strawberry +pear +strawberry +lime +pear +lemon +strawberry +apple +lime +lime +apple +pear +lime +pear +apple +lime +lemon +cherry +apple +lime +lime +cherry +apple +cherry +lime +cherry +cherry +pear +cherry +lemon +strawberry +pear +apple +lemon +cherry +lime +apple +cherry +pear +strawberry +cherry +apple +cherry +lemon +pear +apple diff --git a/challenge-032/simon-proctor/medium-test.txt b/challenge-032/simon-proctor/medium-test.txt new file mode 100644 index 0000000000..db5f561f55 --- /dev/null +++ b/challenge-032/simon-proctor/medium-test.txt @@ -0,0 +1,50 @@ +strawberry +cherry +pear +lemon +strawberry +strawberry +cherry +pear +pear +lemon +lemon +lemon +apple +cherry +apple +strawberry +strawberry +lemon +apple +strawberry +lime +cherry +cherry +strawberry +lime +apple +lime +strawberry +cherry +strawberry +strawberry +lime +strawberry +cherry +cherry +strawberry +apple +pear +lime +lemon +apple +apple +lime +lime +strawberry +pear +pear +lemon +cherry +lime diff --git a/challenge-032/simon-proctor/perl6/ch-1.p6 b/challenge-032/simon-proctor/perl6/ch-1.p6 new file mode 100644 index 0000000000..8253bf56a8 --- /dev/null +++ b/challenge-032/simon-proctor/perl6/ch-1.p6 @@ -0,0 +1,36 @@ +#!/usr/bin/env perl6 + +use v6; + +subset ValidFile of Str where *.IO.f; +my %*SUB-MAIN-OPTS = :named-anywhere; + +#| Print help text +multi sub MAIN( Bool :h($help) where so * ) { + say $*USAGE; +} + +#| Read date from standard out. +#| Returns a list of name and count sorted by count +multi sub MAIN( + Bool :$csv = False #= Output in CSV +) { + read-files( IO::CatHandle.new( $*IN ), $csv ); +} + +#| Given a list of filenames reads each in turn +multi sub MAIN( + *@files where all(@files) ~~ ValidFile, #= Files to read + Bool :$csv = False #= Output in CSV +) { + read-files( IO::CatHandle.new( @files ), $csv ); +} + +sub read-files( IO::CatHandle $files, $csv ) { + my %results := BagHash.new(); + %results{$_}++ for $files.lines; + my $k-dist = %results.keys.map( *.codes ).max; + my $v-dist = %results.values.map( *.codes ).max; + my $fmt = $csv ?? '"%s",%d' !! "% -{$k-dist+2}s%{$v-dist+2}d"; + .say for %results.sort( *.value <=> *.value ).reverse.map( { sprintf($fmt,$_.key,$_.value) } ); +} diff --git a/challenge-032/simon-proctor/perl6/ch-2.p6 b/challenge-032/simon-proctor/perl6/ch-2.p6 new file mode 100644 index 0000000000..6e497adf27 --- /dev/null +++ b/challenge-032/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,84 @@ +#!/usr/bin/env perl6 + +use v6; + +enum SortType <value key>; +enum SortDir <asc desc>; +subset ValidFile of Str where *.IO.f; +my %*SUB-MAIN-OPTS = :named-anywhere; + +#| Print help text +multi sub MAIN( Bool :h($help) where so * ) { + say $*USAGE; +} + +sub read-data( IO::CatHandle $files, Bool $csv ) { + my &line-reader = $csv ?? &parse-csv !! &parse-space-sep; + my %results := BagHash.new(); + $files.lines.map( &line-reader ).map( -> ( $k, $v ) { %results{$k} = $v } ); + return %results; +} + +#| Read data from standard out. +#| Prints a bar chart of the data +multi sub MAIN( + Bool :$csv = False, #= Input in CSV + SortType :$sort-type=value, #= Sort Type + SortDir :$sort-dir=desc, #= Sort Direction +) { + draw-graph( read-data( IO::CatHandle.new( $*IN ), $csv ), $sort-type, $sort-dir ); +} + +#| Given a list of filenames reads each in turn +multi sub MAIN( + *@files where all(@files) ~~ ValidFile, #= Files to read + Bool :$csv = False, #= Output in CSV + SortType :$sort-type=value, #= Sort Type + SortDir :$sort-dir=desc, #= Sort Direction +) { + draw-graph( read-data( IO::CatHandle.new( @files ), $csv ), $sort-type, $sort-dir ); +} + +sub draw-graph( %data, SortType $sort-type, SortDir $sort-dir ) { + my $k-width = %data.keys.map(*.codes).max; + my $max-val = %data.values.max; + my $screen-width = get-screen-width(); + + my &sorter = make-sorter( $sort-type, $sort-dir ); + + my $available = $screen-width - $k-width - 5; + .say for %data.sort( &sorter ).map( { sprintf( "% -{$k-width}s | %s", $_.key, get-bar( $available, $max-val, $_.value ) ) } ); +} + +sub make-sorter( SortType $sort-type, SortDir $sort-dir ) { + given $sort-dir { + when asc { + -> $a, $b { $a.^lookup($sort-type)($a) cmp $b.^lookup($sort-type)($b) } + } + when desc { + -> $a, $b { $b.^lookup($sort-type)($b) cmp $a.^lookup($sort-type)($a) } + } + } +} + +sub get-bar( Int $available, $max, $value ) { + '#' x ceiling( $available * ( $value / $max ) ); +} + +sub get-screen-width() { + run("tput","cols",:out).out.slurp.chomp; +} + +sub parse-space-sep( Str $line ) { + if ( my $match = $line ~~ m!^ (\S+) \s+ (\S+) $! ) { + return $match[0], $match[1]; + } + die "Line parser didn't work on $line"; +} + +sub parse-csv( Str $line ) { + if ( my $match = $line ~~ m!^ (\"?) (.+) $0 "," (.+) $! ) { #" Editor bug + return $match[1], $match[2]; + } + die "Lazy CSV parser didn't work on $line"; +} diff --git a/challenge-032/simon-proctor/small-test.txt b/challenge-032/simon-proctor/small-test.txt new file mode 100644 index 0000000000..00fe021a08 --- /dev/null +++ b/challenge-032/simon-proctor/small-test.txt @@ -0,0 +1,6 @@ +apple +banana +apple +cherry +cherry +apple diff --git a/script/refresh-stats.sh b/script/refresh-stats.sh index 00d8b0275c..c9ad582f8f 100644 --- a/script/refresh-stats.sh +++ b/script/refresh-stats.sh @@ -59,6 +59,8 @@ mv pwc-current.json stats/pwc-challenge-029.json fetch-pwc-stats --members members.json --guests guests.json --source challenge-030 --current mv pwc-current.json stats/pwc-challenge-030.json fetch-pwc-stats --members members.json --guests guests.json --source challenge-031 --current +mv pwc-current.json stats/pwc-challenge-031.json +fetch-pwc-stats --members members.json --guests guests.json --source challenge-032 --current mv pwc-current.json stats/ fetch-pwc-stats --members members.json --guests guests.json --source challenge-001 --summary @@ -91,6 +93,7 @@ fetch-pwc-stats --members members.json --guests guests.json --source challenge-0 fetch-pwc-stats --members members.json --guests guests.json --source challenge-028 --master pwc-summary.json --update fetch-pwc-stats --members members.json --guests guests.json --source challenge-029 --master pwc-summary.json --update fetch-pwc-stats --members members.json --guests guests.json --source challenge-030 --master pwc-summary.json --update +fetch-pwc-stats --members members.json --guests guests.json --source challenge-031 --master pwc-summary.json --update mv pwc-summary.json stats/pwc-master-stats.json echo Now fetch current stats diff --git a/stats/pwc-challenge-031.json b/stats/pwc-challenge-031.json new file mode 100644 index 0000000000..c7ec3c67a7 --- /dev/null +++ b/stats/pwc-challenge-031.json @@ -0,0 +1,599 @@ +{ + "series" : [ + { + "colorByPoint" : 1, + "data" : [ + { + "y" : 5, + "drilldown" : "Adam Russell", + "name" : "Adam Russell" + }, + { + "name" : "Andrezgz", + "y" : 2, + "drilldown" : "Andrezgz" + }, + { + "name" : "Anton Fedotov", + "drilldown" : "Anton Fedotov", + "y" : 2 + }, + { + "name" : "Arne Sommer", + "drilldown" : "Arne Sommer", + "y" : 3 + }, + { + "name" : "Athanasius", + "drilldown" : "Athanasius", + "y" : 4 + }, + { + "name" : "Burkhard Nickels", + "drilldown" : "Burkhard Nickels", + "y" : 2 + }, + { + "drilldown" : "Colin Crain", + "y" : 2, + "name" : "Colin Crain" + }, + { + "y" : 2, + "drilldown" : "Dave Cross", + "name" : "Dave Cross" + }, + { + "y" : 2, + "drilldown" : "Dave Jacoby", + "name" : "Dave Jacoby" + }, + { + "name" : "Duane Powell", + "drilldown" : "Duane Powell", + "y" : 2 + }, + { + "drilldown" : "Duncan C. White", + "y" : 2, + "name" : "Duncan C. White" + }, + { + "name" : "E. Choroba", + "y" : 3, + "drilldown" : "E. Choroba" + }, + { + "y" : 5, + "drilldown" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas" + }, + { + "name" : "Javier Luque", + "drilldown" : "Javier Luque", + "y" : 5 + }, + { + "name" : "Joelle Maslak", + "y" : 4, + "drilldown" : "Joelle Maslak" + }, + { + "name" : "Kevin Colyer", + "drilldown" : "Kevin Colyer", + "y" : 2 + }, + { + "drilldown" : "Lars Balker", + "y" : 2, + "name" : "Lars Balker" + }, + { + "drilldown" : "Lars Thegler", + "y" : 2, + "name" : "Lars Thegler" + }, + { + "name" : "Laurent Rosenfeld", + "y" : 5, + "drilldown" : "Laurent Rosenfeld" + }, + { + "name" : "Lubos Kolouch", + "drilldown" : "Lubos Kolouch", + "y" : 2 + }, + { + "y" : 2, + "drilldown" : "Mark Senn", + "name" : "Mark Senn" + }, + { + "name" : "Markus Holzer", + "y" : 2, + "drilldown" : "Markus Holzer" + }, + { + "name" : "Maxim Kolodyazhny", + "y" : 1, + "drilldown" : "Maxim Kolodyazhny" + }, + { + "y" : 2, + "drilldown" : "Nazareno Delucca", + "name" : "Nazareno Delucca" + }, + { + "drilldown" : "Noud", + "y" : 2, + "name" : "Noud" + }, + { + "name" : "Pete Houston", + "drilldown" : "Pete Houston", + "y" : 1 + }, + { + "name" : "Rage311", + "y" : 2, + "drilldown" : "Rage311" + }, + { + "name" : "Ruben Westerberg", + "y" : 4, + "drilldown" : "Ruben Westerberg" + }, + { + "drilldown" : "Simon Proctor", + "y" : 1, + "name" : "Simon Proctor" + }, + { + "y" : 2, + "drilldown" : "Steven Wilson", + "name" : "Steven Wilson" + }, + { + "name" : "Tyler Limkemann", + "drilldown" : "Tyler Limkemann", + "y" : 2 + }, + { + "name" : "Vyacheslav Volgarev", + "y" : 2, + "drilldown" : "Vyacheslav Volgarev" + }, + { + "drilldown" : "Yet Ebreo", + "y" : 3, + "name" : "Yet Ebreo" + } + ], + "name" : "Perl Weekly Challenge - 031" + } + ], + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "legend" : { + "enabled" : 0 + }, + "drilldown" : { + "series" : [ + { + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Adam Russell", + "id" : "Adam Russell" + }, + { + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "name" : "Andrezgz", + "id" : "Andrezgz" + }, + { + "id" : "Anton Fedotov", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "name" : "Anton Fedotov" + }, + { + "name" : "Arne Sommer", + "data" : [ + [ + "Perl 6", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Arne Sommer" + }, + { + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 2 + ] + ], + "name" : "Athanasius", + "id" : "Athanasius" + }, + { + "id" : "Burkhard Nickels", + "name" : "Burkhard Nickels", + "data" : [ + [ + "Perl 5", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "name" : "Colin Crain", + "id" : "Colin Crain" + }, + { + "id" : "Dave Cross", + "name" : "Dave Cross", + "data" : [ + [ + "Perl 5", + 2 + ] + ] + }, + { + "name" : "Dave Jacoby", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "id" : "Dave Jacoby" + }, + { + "name" : "Duane Powell", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "id" : "Duane Powell" + }, + { + "id" : "Duncan C. White", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "name" : "Duncan C. White" + }, + { + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "E. Choroba", + "id" : "E. Choroba" + }, + { + "id" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas", + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "name" : "Javier Luque", + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Javier Luque" + }, + { + "name" : "Joelle Maslak", + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 2 + ] + ], + "id" : "Joelle Maslak" + }, + { + "id" : "Kevin Colyer", + "name" : "Kevin Colyer", + "data" : [ + [ + "Perl 6", + 2 + ] + ] + }, + { + "name" : "Lars Balker", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "id" : "Lars Balker" + }, + { + "name" : "Lars Thegler", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "id" : "Lars Thegler" + }, + { + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch", + "data" : [ + [ + "Perl 5", + 2 + ] + ] + }, + { + "name" : "Mark Senn", + "data" : [ + [ + "Perl 6", + 2 + ] + ], + "id" : "Mark Senn" + }, + { + "id" : "Markus Holzer", + "data" : [ + [ + "Perl 6", + 2 + ] + ], + "name" : "Markus Holzer" + }, + { + "id" : "Maxim Kolodyazhny", + "name" : "Maxim Kolodyazhny", + "data" : [ + [ + "Perl 5", + 1 + ] + ] + }, + { + "id" : "Nazareno Delucca", + "name" : "Nazareno Delucca", + "data" : [ + [ + "Perl 5", + 2 + ] + ] + }, + { + "name" : "Noud", + "data" : [ + [ + "Perl 6", + 2 + ] + ], + "id" : "Noud" + }, + { + "name" : "Pete Houston", + "data" : [ + [ + "Perl 5", + 1 + ] + ], + "id" : "Pete Houston" + }, + { + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "name" : "Rage311", + "id" : "Rage311" + }, + { + "id" : "Ruben Westerberg", + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 2 + ] + ], + "name" : "Ruben Westerberg" + }, + { + "id" : "Simon Proctor", + "data" : [ + [ + "Perl 6", + 1 + ] + ], + "name" : "Simon Proctor" + }, + { + "id" : "Steven Wilson", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "name" : "Steven Wilson" + }, + { + "id" : "Tyler Limkemann", + "data" : [ + [ + "Perl 6", + 2 + ] + ], + "name" : "Tyler Limkemann" + }, + { + "id" : "Vyacheslav Volgarev", + "name" : "Vyacheslav Volgarev", + "data" : [ + [ + "Perl 5", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl 5", + 2 + ], + [ + "Perl 6", + 1 + ] + ], + "name" : "Yet Ebreo", + "id" : "Yet Ebreo" + } + ] + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "tooltip" : { + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "followPointer" : 1 + }, + "chart" : { + "type" : "column" + }, + "subtitle" : { + "text" : "[Champions: 33] Last updated at 2019-10-27 23:52:12 GMT" + }, + "xAxis" : { + "type" : "category" + }, + "title" : { + "text" : "Perl Weekly Challenge - 031" + } +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index c7ec3c67a7..13cf2f3a67 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,575 +1,42 @@ { - "series" : [ - { - "colorByPoint" : 1, - "data" : [ - { - "y" : 5, - "drilldown" : "Adam Russell", - "name" : "Adam Russell" - }, - { - "name" : "Andrezgz", - "y" : 2, - "drilldown" : "Andrezgz" - }, - { - "name" : "Anton Fedotov", - "drilldown" : "Anton Fedotov", - "y" : 2 - }, - { - "name" : "Arne Sommer", - "drilldown" : "Arne Sommer", - "y" : 3 - }, - { - "name" : "Athanasius", - "drilldown" : "Athanasius", - "y" : 4 - }, - { - "name" : "Burkhard Nickels", - "drilldown" : "Burkhard Nickels", |
