diff options
| -rw-r--r-- | challenge-032/colin-crain/perl5/ch-1.pl | 72 | ||||
| -rw-r--r-- | challenge-032/colin-crain/perl5/ch-2.pl | 110 | ||||
| -rw-r--r-- | stats/pwc-current.json | 229 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 40 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 258 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 940 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 128 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 42 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 54 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 38 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 96 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 310 |
12 files changed, 1257 insertions, 1060 deletions
diff --git a/challenge-032/colin-crain/perl5/ch-1.pl b/challenge-032/colin-crain/perl5/ch-1.pl new file mode 100644 index 0000000000..2c24d6ed1d --- /dev/null +++ b/challenge-032/colin-crain/perl5/ch-1.pl @@ -0,0 +1,72 @@ +#! /opt/local/bin/perl +# +# counter.pl +# +# PWC32 - 1 +# Count instances +# 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. +# +# So with the following input in file example.txt +# +# apple +# banana +# apple +# cherry +# cherry +# apple +# the script would display something like: +# +# apple 3 +# cherry 2 +# banana 1 +# For extra credit, add a -csv option to your script, which would generate: +# +# apple,3 +# cherry,2 +# banana,1 +# +# +# colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +use warnings; +use strict; +use feature ":5.26"; + +## ## ## ## ## MAIN + +my @args = @ARGV || './example.txt'; ## only so we can run it from the editor +my $counter = {}; + +if ( -f $args[0] ) { +## its a list of files + for my $file ( @args ) { + open (my $fh, "<", $file); + my @lines = <$fh>; + close $fh; + + for my $line ( @lines ){ + chomp $line; + $counter->{$line}++; + } + } +} +else { +## it's just a STDIN list of words + my @lines = @args; + for my $line ( @lines ){ + chomp $line; + $counter->{$line}++; + } +} + +for my $key (sort keys $counter->%*) { + printf "%-10s %-d\n", $key, $counter->{$key}; + +} + + diff --git a/challenge-032/colin-crain/perl5/ch-2.pl b/challenge-032/colin-crain/perl5/ch-2.pl new file mode 100644 index 0000000000..c7638ba845 --- /dev/null +++ b/challenge-032/colin-crain/perl5/ch-2.pl @@ -0,0 +1,110 @@ +#! /opt/local/bin/perl +# +# grapher.pl +# +# PWC32 - 2 +# 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. +# +# The input could be something like: +# $data = { apple => 3, cherry => 2, banana => 1 }; +# generate_bar_graph($data); +# +# And would then generate something like this: +# +# apple | ############ +# cherry | ######## +# banana | #### +# +# If you fancy then please try this as well: (a) the function could +# let you specify whether the chart should be ordered by (1) the +# labels, or (2) the values. +# +# +# +# colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +use warnings; +use strict; +use feature ":5.26"; + +## ## ## ## ## MAIN + +my $data = { + 'a' => 10.3, + 'b' => 20.9, + 'c' => 35, + 'd' => 85.5, + 'f' => 2, + 'h' => -85.5, + 'i' => 83.5 +}; + +generate_graph_80( $data ); + + +## ## ## ## ## SUBS + +sub generate_graph_simple { +## a simplest version, with horizontal bars and each 'x' representing the count of 1 +## this can't handle negative values + my $data = shift; + foreach (sort keys $data->%*) { + say "$_\t", '=' x $data->{$_}; + }; +} + +sub generate_graph_80 { +## normalizes the data set to span 80 increments, rounding individual points to the nearest +## also adds a x-axis label. +## normalizing sets the start at the smallest value, so the vacant bar is not an error. +# +## adding an auto-adjustment to the x-axis would be the next step, but this is +## not obvious in its implementation, as there are no constraints placed on the input data. +## the algoritm needs to discreetly step up units when appropriate. +## for example this example would be more clear if the axis ranged from -100 to +100, but +## automatically selecting that from the given data is complex. +## adjusting the bars to the selected axis sequence is just a variant application of the +## techniques used here for normalization. + my $data = shift; + + my $width = 80; + my ($min, $max, $range) = get_range( $data ); + + foreach (sort keys $data->%*) { + my $normalized = ($data->{$_} - $min) * $width / $range; + my $adjusted_value = round( $normalized ); + + printf "%9s |%-s\n", $_, '=' x $adjusted_value; + }; + + my $x_axis; + $x_axis = join '', map { $_ % 4 == 0 ? "|" : "-"} ( 0..($width) ); + printf "%9s %-s\n", "", $x_axis; + + my $x_numeric; + for my $idx ( 0..($width) ) { + my $point = sprintf "%-7s " , $min + ($range / $width * $idx) ; + $x_numeric .= $idx % 8 == 0 ? $point : ""; + } + printf "%9s %s\n", "", $x_numeric; +} + +sub round { +## rounds positive and negative integer and float data correctly + return int($_[0] + $_[0]/abs($_[0]*2 || 1)); +} + +sub get_range { +## given a hashref containing a data set, finds the minimum, maximum, and absolute range of values + my $data = shift; + my @values = sort {$a <=> $b} values $data->%*; + my ($min, $max) = ($values[0], $values[(scalar @values) - 1]); + my $range = $max - $min; + return ($min, $max, $range); + +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 77122ee132..d2515a513e 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,7 +1,4 @@ { - "legend" : { - "enabled" : 0 - }, "drilldown" : { "series" : [ { @@ -23,24 +20,24 @@ ] }, { + "id" : "Andrezgz", "name" : "Andrezgz", "data" : [ [ "Perl 5", 2 ] - ], - "id" : "Andrezgz" + ] }, { - "id" : "Anton Fedotov", "name" : "Anton Fedotov", "data" : [ [ "Perl 5", 2 ] - ] + ], + "id" : "Anton Fedotov" }, { "data" : [ @@ -71,6 +68,7 @@ "name" : "Athanasius" }, { + "id" : "Burkhard Nickels", "name" : "Burkhard Nickels", "data" : [ [ @@ -81,28 +79,37 @@ "Blog", 1 ] - ], - "id" : "Burkhard Nickels" + ] + }, + { + "id" : "Colin Crain", + "name" : "Colin Crain", + "data" : [ + [ + "Perl 5", + 2 + ] + ] }, { - "name" : "Dave Cross", "data" : [ [ "Perl 5", 2 ] ], + "name" : "Dave Cross", "id" : "Dave Cross" }, { "id" : "Dave Jacoby", - "name" : "Dave Jacoby", "data" : [ [ "Perl 5", 2 ] - ] + ], + "name" : "Dave Jacoby" }, { "name" : "Duane Powell", @@ -126,26 +133,25 @@ }, { "id" : "Fabrizio Poggi", + "name" : "Fabrizio Poggi", "data" : [ [ "Perl 5", 2 ] - ], - "name" : "Fabrizio Poggi" + ] }, { - "name" : "Giuseppe Di Terlizzi", "data" : [ [ "Perl 5", 2 ] ], + "name" : "Giuseppe Di Terlizzi", "id" : "Giuseppe Di Terlizzi" }, { - "id" : "Javier Luque", "data" : [ [ "Perl 5", @@ -160,10 +166,10 @@ 1 ] ], - "name" : "Javier Luque" + "name" : "Javier Luque", + "id" : "Javier Luque" }, { - "id" : "Joelle Maslak", "name" : "Joelle Maslak", "data" : [ [ @@ -174,17 +180,18 @@ "Perl 6", 2 ] - ] + ], + "id" : "Joelle Maslak" }, { + "id" : "Kevin Colyer", + "name" : "Kevin Colyer", "data" : [ [ "Perl 6", 2 ] - ], - "name" : "Kevin Colyer", - "id" : "Kevin Colyer" + ] }, { "id" : "Lars Balker", @@ -207,6 +214,8 @@ "id" : "Lars Thegler" }, { + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld", "data" : [ [ "Perl 5", @@ -220,9 +229,7 @@ "Blog", 1 ] - ], - "name" : "Laurent Rosenfeld", - "id" : "Laurent Rosenfeld" + ] }, { "id" : "Markus Holzer", @@ -235,14 +242,14 @@ "name" : "Markus Holzer" }, { - "id" : "Nazareno Delucca", "name" : "Nazareno Delucca", "data" : [ [ "Perl 5", 2 ] - ] + ], + "id" : "Nazareno Delucca" }, { "name" : "Noud", @@ -255,34 +262,34 @@ "id" : "Noud" }, { - "id" : "Prajith P", "data" : [ [ "Perl 5", 2 ] ], - "name" : "Prajith P" + "name" : "Prajith P", + "id" : "Prajith P" }, { + "id" : "Rage311", + "name" : "Rage311", "data" : [ [ "Perl 5", 2 ] - ], - "name" : "Rage311", - "id" : "Rage311" + ] }, { - "name" : "Roger Bell West", + "id" : "Roger Bell West", "data" : [ [ "Perl 5", 2 ] ], - "id" : "Roger Bell West" + "name" : "Roger Bell West" }, { "data" : [ @@ -299,85 +306,65 @@ "id" : "Ryan Thompson" }, { - "name" : "Simon Proctor", + "id" : "Simon Proctor", "data" : [ [ "Perl 6", 2 ] ], - "id" : "Simon Proctor" + "name" : "Simon Proctor" }, { "id" : "Steven Wilson", - "name" : "Steven Wilson", "data" : [ [ "Perl 5", 2 ] - ] + ], + "name" : "Steven Wilson" }, { + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", "data" : [ [ "Perl 5", 2 ] - ], - "name" : "Ulrich Rieke", - "id" : "Ulrich Rieke" + ] }, { - "name" : "Yet Ebreo", "data" : [ [ "Perl 5", 2 ] ], + "name" : "Yet Ebreo", "id" : "Yet Ebreo" } ] }, - "subtitle" : { - "text" : "[Champions: 29] Last updated at 2019-11-03 22:28:03 GMT" + "xAxis" : { + "type" : "category" }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, - "chart" : { - "type" : "column" - }, - "tooltip" : { - "followPointer" : 1, - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } - } - }, - "xAxis" : { - "type" : "category" - }, - "title" : { - "text" : "Perl Weekly Challenge - 032" + "legend" : { + "enabled" : 0 }, "series" : [ { "name" : "Perl Weekly Challenge - 032", "data" : [ { - "y" : 5, "drilldown" : "Adam Russell", + "y" : 5, "name" : "Adam Russell" }, { @@ -396,9 +383,9 @@ "drilldown" : "Arne Sommer" }, { - "name" : "Athanasius", + "drilldown" : "Athanasius", "y" : 4, - "drilldown" : "Athanasius" + "name" : "Athanasius" }, { "name" : "Burkhard Nickels", @@ -406,79 +393,84 @@ "y" : 3 }, { - "name" : "Dave Cross", + "name" : "Colin Crain", + "drilldown" : "Colin Crain", + "y" : 2 + }, + { "y" : 2, - "drilldown" : "Dave Cross" + "drilldown" : "Dave Cross", + "name" : "Dave Cross" }, { - "name" : "Dave Jacoby", + "drilldown" : "Dave Jacoby", "y" : 2, - "drilldown" : "Dave Jacoby" + "name" : "Dave Jacoby" }, { + "name" : "Duane Powell", "y" : 2, - "drilldown" : "Duane Powell", - "name" : "Duane Powell" + "drilldown" : "Duane Powell" }, { "name" : "E. Choroba", - "y" : 2, - "drilldown" : "E. Choroba" + "drilldown" : "E. Choroba", + "y" : 2 }, { - "name" : "Fabrizio Poggi", "y" : 2, - "drilldown" : "Fabrizio Poggi" + "drilldown" : "Fabrizio Poggi", + "name" : "Fabrizio Poggi" }, { - "y" : 2, + "name" : "Giuseppe Di Terlizzi", "drilldown" : "Giuseppe Di Terlizzi", - "name" : "Giuseppe Di Terlizzi" + "y" : 2 }, { - "name" : "Javier Luque", + "y" : 5, "drilldown" : "Javier Luque", - "y" : 5 + "name" : "Javier Luque" }, { - "drilldown" : "Joelle Maslak", + "name" : "Joelle Maslak", "y" : 4, - "name" : "Joelle Maslak" + "drilldown" : "Joelle Maslak" }, { - "name" : "Kevin Colyer", "drilldown" : "Kevin Colyer", - "y" : 2 + "y" : 2, + "name" : "Kevin Colyer" }, { + "name" : "Lars Balker", "y" : 2, - "drilldown" : "Lars Balker", - "name" : "Lars Balker" + "drilldown" : "Lars Balker" }, { - "y" : 2, "drilldown" : "Lars Thegler", + "y" : 2, "name" : "Lars Thegler" }, { + "name" : "Laurent Rosenfeld", "drilldown" : "Laurent Rosenfeld", - "y" : 5, - "name" : "Laurent Rosenfeld" + "y" : 5 }, { - "y" : 2, "drilldown" : "Markus Holzer", + "y" : 2, "name" : "Markus Holzer" }, { - "name" : "Nazareno Delucca", + "y" : 2, "drilldown" : "Nazareno Delucca", - "y" : 2 + "name" : "Nazareno Delucca" }, { "name" : "Noud", - "drilldown" : "Noud", - "y" : 2 + "y" : 2, + "drilldown" : "Noud" }, { "y" : 2, @@ -491,24 +483,24 @@ "name" : "Rage311" }, { + "name" : "Roger Bell West", "drilldown" : "Roger Bell West", - "y" : 2, - "name" : "Roger Bell West" + "y" : 2 }, { + "name" : "Ryan Thompson", "drilldown" : "Ryan Thompson", - "y" : 3, - "name" : "Ryan Thompson" + "y" : 3 }, { - "drilldown" : "Simon Proctor", + "name" : "Simon Proctor", "y" : 2, - "name" : "Simon Proctor" + "drilldown" : "Simon Proctor" }, { + "name" : "Steven Wilson", "drilldown" : "Steven Wilson", - "y" : 2, - "name" : "Steven Wilson" + "y" : 2 }, { "y" : 2, @@ -516,12 +508,35 @@ "name" : "Ulrich Rieke" }, { - "drilldown" : "Yet Ebreo", "y" : 2, + "drilldown" : "Yet Ebreo", "name" : "Yet Ebreo" } ], "colorByPoint" : 1 } - ] + ], + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "tooltip" : { + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : 1 + }, + "chart" : { + "type" : "column" + }, + "subtitle" : { + "text" : "[Champions: 30] Last updated at 2019-11-03 22:35:33 GMT" + }, + "title" : { + "text" : "Perl Weekly Challenge - 032" + } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 260f8ec0a4..5f65793692 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,34 +1,40 @@ { + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, "xAxis" : { - "type" : "category", "labels" : { "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" } - } + }, + "type" : "category" }, - "subtitle" : { - "text" : "Last updated at 2019-11-03 22:28:09 GMT" + "title" : { + "text" : "Perl Weekly Challenge Contributions - 2019" }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" + "legend" : { + "enabled" : "false" + }, + "subtitle" : { + "text" : "Last updated at 2019-11-03 22:35:49 GMT" }, "series" : [ { + "name" : "Contributions", "dataLabels" : { - "y" : 10, + "color" : "#FFFFFF", "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" }, "enabled" : "true", - "color" : "#FFFFFF", + "y" : 10, "rotation" : -90, "format" : "{point.y:.0f}", "align" : "right" }, - "name" : "Contributions", "data" : [ [ "Blog", @@ -36,7 +42,7 @@ ], [ "Perl 5", - 1353 + 1355 ], [ "Perl 6", @@ -45,19 +51,13 @@ ] } ], - "title" : { - "text" : "Perl Weekly Challenge Contributions - 2019" + "chart" : { + "type" : "column" }, "yAxis" : { "min" : 0, "title" : { "text" : null } - }, - "legend" : { - "enabled" : "false" - }, - "chart" : { - "type" : "column" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 6b4268337c..84e7123795 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,17 +1,39 @@ { + "legend" : { + "enabled" : "false" + }, + "tooltip" : { + "headerFormat" : "<span style=\"font-size:11px\"></span>", + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : "true" + }, + "xAxis" : { + "type" : "category" + }, + "title" : { + "text" : "Perl Weekly Challenge Language" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2019-11-03 22:35:49 GMT" + }, "series" : [ { "name" : "Perl Weekly Challenge Languages", "colorByPoint" : "true", "data" : [ { - "y" : 132, + "drilldown" : "001", "name" : "#001", - "drilldown" : "001" + "y" : 132 }, { - "name" : "#002", "drilldown" : "002", + "name" : "#002", "y" : 104 }, { @@ -25,24 +47,24 @@ "name" : "#004" }, { - "y" : 66, + "drilldown" : "005", "name" : "#005", - "drilldown" : "005" + "y" : 66 }, { - "y" : 48, + "drilldown" : "006", "name" : "#006", - "drilldown" : "006" + "y" : 48 }, { - "name" : "#007", "drilldown" : "007", + "name" : "#007", "y" : 56 }, { - "y" : 70, "name" : "#008", - "drilldown" : "008" + "drilldown" : "008", + "y" : 70 }, { "y" : 68, @@ -50,29 +72,29 @@ "drilldown" : "009" }, { + "y" : 60, "drilldown" : "010", - "name" : "#010", - "y" : 60 + "name" : "#010" }, { "y" : 78, - "drilldown" : "011", - "name" : "#011" + "name" : "#011", + "drilldown" : "011" }, { - "y" : 83, + "drilldown" : "012", "name" : "#012", - "drilldown" : "012" + "y" : 83 }, { "y" : 76, - "drilldown" : "013", - "name" : "#013" + "name" : "#013", + "drilldown" : "013" }, { - "y" : 96, "name" : "#014", - "drilldown" : "014" + "drilldown" : "014", + "y" : 96 }, { "y" : 93, @@ -80,9 +102,9 @@ "name" : "#015" }, { - "y" : 66, + "drilldown" : "016", "name" : "#016", - "drilldown" : "016" + "y" : 66 }, { "y" : 79, @@ -90,18 +112,18 @@ "name" : "#017" }, { - "y" : 76, + "drilldown" : "018", "name" : "#018", - "drilldown" : "018" + "y" : 76 }, { - "y" : 95, "drilldown" : "019", - "name" : "#019" + "name" : "#019", + "y" : 95 }, { - "drilldown" : "020", "name" : "#020", + "drilldown" : "020", "y" : 95 }, { @@ -110,9 +132,9 @@ "drilldown" : "021" }, { + "y" : 63, "drilldown" : "022", - "name" : "#022", - "y" : 63 + "name" : "#022" }, { "y" : 91, @@ -126,23 +148,23 @@ }, { "y" : 55, - "name" : "#025", - "drilldown" : "025" + "drilldown" : "025", + "name" : "#025" }, { "y" : 70, - "drilldown" : "026", - "name" : "#026" + "name" : "#026", + "drilldown" : "026" }, { - "y" : 58, + "drilldown" : "027", "name" : "#027", - "drilldown" : "027" + "y" : 58 }, { + "y" : 78, "name" : "#028", - "drilldown" : "028", - "y" : 78 + "drilldown" : "028" }, { "drilldown" : "029", @@ -155,49 +177,22 @@ "drilldown" : "030" }, { + "y" : 86, "drilldown" : "031", - "name" : "#031", - "y" : 86 + "name" : "#031" }, { + "y" : 77, "name" : "#032", - "drilldown" : "032", - "y" : 75 + "drilldown" : "032" } ] } ], - "title" : { - "text" : "Perl Weekly Challenge Language" - }, - "chart" : { - "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "legend" : { - "enabled" : "false" - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - }, - "borderWidth" : 0 - } - }, - "xAxis" : { - "type" : "category" - }, "drilldown" : { "series" : [ { "id" : "001", - "name" : "001", "data" : [ [ "Perl 5", @@ -211,7 +206,8 @@ "Blog", 11 ] - ] + ], + "name" : "001" }, { "data" : [ @@ -228,11 +224,10 @@ 9 ] ], - "name" : "002", - "id" : "002" + "id" : "002", + "name" : "002" }, { - "name" : "003", "data" : [ [ "Perl 5", @@ -247,9 +242,11 @@ 9 ] ], - "id" : "003" + "id" : "003", + "name" : "003" }, { + "name" : "004", "data" : [ [ "Perl 5", @@ -264,11 +261,9 @@ 9 ] ], - "name" : "004", "id" : "004" }, { - "id" : "005", "name" : "005", "data" : [ [ @@ -283,9 +278,11 @@ "Blog", 11 ] - ] + ], + "id" : "005" }, { + "id" : "006", "data" : [ [ "Perl 5", @@ -300,10 +297,10 @@ 7 ] ], - "name" : "006", - "id" : "006" + "name" : "006" }, { + "name" : "007", "id" : "007", "data" : [ [ @@ -318,8 +315,7 @@ "Blog", 10 ] - ], - "name" : "007" + ] }, |
