diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-02-05 07:57:22 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-02-05 07:57:22 +0000 |
| commit | 058c1a99b31cd3ce5b6c6b9d1dd3e609b9b9acb9 (patch) | |
| tree | 50a5d061917fd271fbbe131791712bf5490590e2 | |
| parent | ac93068a90b83de448d144893311d9a5e95c72f8 (diff) | |
| download | perlweeklychallenge-club-058c1a99b31cd3ce5b6c6b9d1dd3e609b9b9acb9.tar.gz perlweeklychallenge-club-058c1a99b31cd3ce5b6c6b9d1dd3e609b9b9acb9.tar.bz2 perlweeklychallenge-club-058c1a99b31cd3ce5b6c6b9d1dd3e609b9b9acb9.zip | |
- Added solutions by Pete Houston.
| -rw-r--r-- | challenge-098/pete-houston/perl/ch-1.pl | 51 | ||||
| -rw-r--r-- | challenge-098/pete-houston/perl/ch-2.pl | 62 | ||||
| -rw-r--r-- | stats/pwc-current.json | 285 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 64 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 708 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 390 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 110 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 32 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 116 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 50 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 102 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 42 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 94 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 50 |
15 files changed, 1165 insertions, 1037 deletions
diff --git a/challenge-098/pete-houston/perl/ch-1.pl b/challenge-098/pete-houston/perl/ch-1.pl new file mode 100644 index 0000000000..0a6a5e7ea7 --- /dev/null +++ b/challenge-098/pete-houston/perl/ch-1.pl @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: 9801.pl +# +# USAGE: ./9801.pl FILENAME [ ENCODING ] +# +# DESCRIPTION: Read N chars (not bytes!) at a time by filename (not handle!) +# +# OPTIONS: The encoding defaults to "utf-8" if unspecifiied. +# REQUIREMENTS: Perl 5.10 or later (for 'state') +# NOTES: The script does very little - it's just a demo of readN +# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk +# ORGANIZATION: Openstrike +# VERSION: 1.0 +# CREATED: 01/02/21 +#=============================================================================== + +use strict; +use warnings; +use feature 'state'; + +my ($filename, $ENC) = @ARGV; +$ENC //= 'utf-8'; +binmode STDOUT, ":encoding($ENC)"; + +my $len = 4; + +# Read and print the whole file, $len characters at a time +while (my $data = readN ($filename, $len)) { + print "$data\n"; + last if $len > length $data; +} + +sub readN { + my ($filename, $len) = @_; + state %handles; + + unless (exists $handles{$filename}) { + open $handles{$filename}, "<:encoding($ENC)", $filename or + die "Cannot open $ENC-encoded file $filename for reading: $!"; + } + my $chars = sysread $handles{$filename}, (my $text), $len; + unless ($chars == $len) { + # We have reached the end of the file. Close the handle and + # remove it from the hash + close $handles{$filename}; + delete $handles{$filename}; + } + return $text; +} diff --git a/challenge-098/pete-houston/perl/ch-2.pl b/challenge-098/pete-houston/perl/ch-2.pl new file mode 100644 index 0000000000..56a54a0711 --- /dev/null +++ b/challenge-098/pete-houston/perl/ch-2.pl @@ -0,0 +1,62 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: 9802.pl +# +# USAGE: ./9802.pl ITEM N [ N ... ] +# +# DESCRIPTION: Find or insert ITEM into list of ascending N +# +# NOTES: Assumes all inputs are integers and the list is sorted +# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk +# ORGANIZATION: Openstrike +# VERSION: 1.0 +# CREATED: 01/02/21 +#=============================================================================== + +use strict; +use warnings; + +my ($new, @n) = @ARGV; + +my $pos = find_or_insert ($new, \@n); +print "$new is at index $pos\nArray is now @n\n"; + +sub find_or_insert { + my ($new, $n) = @_; + + # Is it outside the range? + if ($new < $n->[0]) { + unshift @$n, $new; + return 0; + } + if ($new > $n->[-1]) { + push @$n, $new; + return $#$n; + } + + # Initial boundaries + my $low = 0; + my $high = $#$n; + + # Loop until the boundaries touch + while ($high - $low > 1) { + for ($low, $high) { + return $_ if $n->[$_] == $new; + } + + # Somewhere in between so apply binary search + my $target = $low + int (($high - $low) / 2); + return $target if $n->[$target] == $new; + + if ($new < $n->[$target]) { + $high = $target; + } else { + $low = $target; + } + } + + # Not in the list, so insert it. + splice @$n, $high, 0, $new; + return $high; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 72939cdff0..d75befd4b9 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,95 +1,25 @@ { - "subtitle" : { - "text" : "[Champions: 15] Last updated at 2021-02-05 07:33:52 GMT" + "xAxis" : { + "type" : "category" }, - "series" : [ - { - "colorByPoint" : 1, - "name" : "Perl Weekly Challenge - 098", - "data" : [ - { - "drilldown" : "Andinus", - "name" : "Andinus", - "y" : 2 - }, - { - "y" : 2, - "name" : "Dave Cross", - "drilldown" : "Dave Cross" - }, - { - "drilldown" : "Dave Jacoby", - "y" : 3, - "name" : "Dave Jacoby" - }, - { - "y" : 4, - "name" : "Flavio Poletti", - "drilldown" : "Flavio Poletti" - }, - { - "drilldown" : "Gustavo Chaves", - "name" : "Gustavo Chaves", - "y" : 2 - }, - { - "drilldown" : "James Smith", - "name" : "James Smith", - "y" : 2 - }, - { - "name" : "Luca Ferrari", - "y" : 4, - "drilldown" : "Luca Ferrari" - }, - { - "drilldown" : "Mark Anderson", - "name" : "Mark Anderson", - "y" : 2 - }, - { - "drilldown" : "Nuno Vieira", - "name" : "Nuno Vieira", - "y" : 2 - }, - { - "name" : "Paulo Custodio", - "y" : 2, - "drilldown" : "Paulo Custodio" - }, - { - "y" : 2, - "name" : "Philip Hood", - "drilldown" : "Philip Hood" - }, - { - "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West", - "y" : 4 - }, - { - "drilldown" : "Simon Proctor", - "y" : 2, - "name" : "Simon Proctor" - }, - { - "name" : "Stuart Little", - "y" : 4, - "drilldown" : "Stuart Little" - }, - { - "drilldown" : "W. Luis Mochan", - "y" : 3, - "name" : "W. Luis Mochan" - } - ] + "title" : { + "text" : "Perl Weekly Challenge - 098" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } } - ], + }, + "chart" : { + "type" : "column" + }, "drilldown" : { "series" : [ { - "name" : "Andinus", - "id" : "Andinus", "data" : [ [ "Raku", @@ -99,7 +29,9 @@ "Blog", 1 ] - ] + ], + "name" : "Andinus", + "id" : "Andinus" }, { "data" : [ @@ -122,10 +54,12 @@ 1 ] ], - "name" : "Dave Jacoby", - "id" : "Dave Jacoby" + "id" : "Dave Jacoby", + "name" : "Dave Jacoby" }, { + "name" : "Flavio Poletti", + "id" : "Flavio Poletti", "data" : [ [ "Perl", @@ -135,19 +69,17 @@ "Blog", 2 ] - ], - "id" : "Flavio Poletti", - "name" : "Flavio Poletti" + ] }, { - "id" : "Gustavo Chaves", - "name" : "Gustavo Chaves", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Gustavo Chaves", + "id" : "Gustavo Chaves" }, { "data" : [ @@ -156,12 +88,12 @@ 2 ] ], - "name" : "James Smith", - "id" : "James Smith" + "id" : "James Smith", + "name" : "James Smith" }, { - "name" : "Luca Ferrari", "id" : "Luca Ferrari", + "name" : "Luca Ferrari", "data" : [ [ "Raku", @@ -174,34 +106,44 @@ ] }, { - "id" : "Mark Anderson", - "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] + ], + "name" : "Mark Anderson", + "id" : "Mark Anderson" + }, + { + "name" : "Nuno Vieira", + "id" : "Nuno Vieira", + "data" : [ + [ + "Perl", + 2 + ] ] }, { + "name" : "Paulo Custodio", + "id" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] - ], - "name" : "Nuno Vieira", - "id" : "Nuno Vieira" + ] }, { + "id" : "Pete Houston", + "name" : "Pete Houston", "data" : [ [ "Perl", 2 ] - ], - "name" : "Paulo Custodio", - "id" : "Paulo Custodio" + ] }, { "data" : [ @@ -224,8 +166,8 @@ 2 ] ], - "name" : "Roger Bell_West", - "id" : "Roger Bell_West" + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" }, { "data" : [ @@ -234,10 +176,12 @@ 2 ] ], - "name" : "Simon Proctor", - "id" : "Simon Proctor" + "id" : "Simon Proctor", + "name" : "Simon Proctor" }, { + "id" : "Stuart Little", + "name" : "Stuart Little", "data" : [ [ "Perl", @@ -247,13 +191,9 @@ "Raku", 2 ] - ], - "id" : "Stuart Little", - "name" : "Stuart Little" + ] }, { - "id" : "W. Luis Mochan", - "name" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -263,26 +203,16 @@ "Blog", 1 ] - ] + ], + "name" : "W. Luis Mochan", + "id" : "W. Luis Mochan" } ] }, "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 - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } - } - }, - "xAxis" : { - "type" : "category" + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" }, "yAxis" : { "title" : { @@ -292,10 +222,95 @@ "legend" : { "enabled" : 0 }, - "title" : { - "text" : "Perl Weekly Challenge - 098" + "subtitle" : { + "text" : "[Champions: 16] Last updated at 2021-02-05 07:56:17 GMT" }, - "chart" : { - "type" : "column" - } + "series" : [ + { + "data" : [ + { + "y" : 2, + "name" : "Andinus", + "drilldown" : "Andinus" + }, + { + "drilldown" : "Dave Cross", + "y" : 2, + "name" : "Dave Cross" + }, + { + "y" : 3, + "name" : "Dave Jacoby", + "drilldown" : "Dave Jacoby" + }, + { + "name" : "Flavio Poletti", + "y" : 4, + "drilldown" : "Flavio Poletti" + }, + { + "name" : "Gustavo Chaves", + "y" : 2, + "drilldown" : "Gustavo Chaves" + }, + { + "y" : 2, + "name" : "James Smith", + "drilldown" : "James Smith" + }, + { + "name" : "Luca Ferrari", + "y" : 4, + "drilldown" : "Luca Ferrari" + }, + { + "name" : "Mark Anderson", + "y" : 2, + "drilldown" : "Mark Anderson" + }, + { + "drilldown" : "Nuno Vieira", + "name" : "Nuno Vieira", + "y" : 2 + }, + { + "y" : 2, + "name" : "Paulo Custodio", + "drilldown" : "Paulo Custodio" + }, + { + "drilldown" : "Pete Houston", + "name" : "Pete Houston", + "y" : 2 + }, + { + "y" : 2, + "name" : "Philip Hood", + "drilldown" : "Philip Hood" + }, + { + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West", + "y" : 4 + }, + { + "drilldown" : "Simon Proctor", + "y" : 2, + "name" : "Simon Proctor" + }, + { + "drilldown" : "Stuart Little", + "y" : 4, + "name" : "Stuart Little" + }, + { + "drilldown" : "W. Luis Mochan", + "name" : "W. Luis Mochan", + "y" : 3 + } + ], + "colorByPoint" : 1, + "name" : "Perl Weekly Challenge - 098" + } + ] } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 0f392da192..0bea45e5f4 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,13 +1,19 @@ { - "subtitle" : { - "text" : "Last updated at 2021-02-05 07:33:52 GMT" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, "series" : [ { "name" : "Contributions", + "dataLabels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + }, + "color" : "#FFFFFF", + "format" : "{point.y:.0f}", + "align" : "right", + "rotation" : -90, + "y" : 10, + "enabled" : "true" + }, "data" : [ [ "Blog", @@ -15,35 +21,17 @@ ], [ "Perl", - 4551 + 4553 ], [ "Raku", 2949 ] - ], - "dataLabels" : { - "y" : 10, - "color" : "#FFFFFF", - "rotation" : -90, - "format" : "{point.y:.0f}", - "align" : "right", - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, - "enabled" : "true" - } + ] } ], - "xAxis" : { - "type" : "category", - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } - } + "legend" : { + "enabled" : "false" }, "yAxis" : { "min" : 0, @@ -51,13 +39,25 @@ "text" : null } }, - "legend" : { - "enabled" : "false" + "subtitle" : { + "text" : "Last updated at 2021-02-05 07:56:17 GMT" }, - "title" : { - "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" }, "chart" : { "type" : "column" + }, + "title" : { + "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" + }, + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + } + } } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 1885f0ce0b..23226ed613 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,35 +1,7 @@ { - "legend" : { - "enabled" : "false" - }, - "title" : { - "text" : "Perl Weekly Challenge Language" - }, - "chart" : { - "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2021-02-05 07:33:52 GMT" - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } - }, "drilldown" : { "series" : [ { - "id" : "001", - "name" : "001", "data" : [ [ "Perl", @@ -43,9 +15,13 @@ "Blog", 11 ] - ] + ], + "name" : "001", + "id" : "001" }, { + "id" : "002", + "name" : "002", "data" : [ [ "Perl", @@ -59,9 +35,7 @@ "Blog", 10 ] - ], - "id" : "002", - "name" : "002" + ] }, { "name" : "003", @@ -82,8 +56,6 @@ ] }, { - "id" : "004", - "name" : "004", "data" : [ [ "Perl", @@ -97,7 +69,9 @@ "Blog", 10 ] - ] + ], + "id" : "004", + "name" : "004" }, { "data" : [ @@ -114,10 +88,12 @@ 12 ] ], - "id" : "005", - "name" : "005" + "name" : "005", + "id" : "005" }, { + "id" : "006", + "name" : "006", "data" : [ [ "Perl", @@ -131,13 +107,11 @@ "Blog", 7 ] - ], - "id" : "006", - "name" : "006" + ] }, { - "name" : "007", "id" : "007", + "name" : "007", "data" : [ [ "Perl", @@ -154,6 +128,8 @@ ] }, { + "id" : "008", + "name" : "008", "data" : [ [ "Perl", @@ -167,9 +143,7 @@ "Blog", 12 ] - ], - "id" : "008", - "name" : "008" + ] }, { "data" : [ @@ -208,8 +182,6 @@ ] }, { - "id" : "011", - "name" : "011", "data" : [ [ "Perl", @@ -223,11 +195,13 @@ "Blog", 10 ] - ] + ], + "name" : "011", + "id" : "011" }, { - "name" : "012", "id" : "012", + "name" : "012", "data" : [ [ "Perl", @@ -244,6 +218,8 @@ ] }, { + "name" : "013", + "id" : "013", "data" : [ [ "Perl", @@ -257,9 +233,7 @@ "Blog", 13 ] - ], - "id" : "013", - "name" : "013" + ] }, { "data" : [ @@ -276,12 +250,10 @@ 15 ] ], - "name" : "014", - "id" : "014" + "id" : "014", + "name" : "014" }, { - "id" : "015", - "name" : "015", "data" : [ [ "Perl", @@ -295,11 +267,13 @@ "Blog", 15 ] - ] + ], + "id" : "015", + "name" : "015" }, { - "name" : "016", "id" : "016", + "name" : "016", "data" : [ [ "Perl", @@ -330,12 +304,12 @@ 12 ] ], - "id" : "017", - "name" : "017" + "name" : "017", + "id" : "017" }, { - "id" : "018", "name" : "018", + "id" : "018", "data" : [ [ "Perl", @@ -366,12 +340,10 @@ 13 ] ], - "name" : "019", - "id" : "019" + "id" : "019", + "name" : "019" }, { - "id" : "020", - "name" : "020", "data" : [ [ "Perl", @@ -385,11 +357,11 @@ "Blog", 13 ] - ] + ], + "name" : "020", + "id" : "020" }, { - "id" : "021", - "name" : "021", "data" : [ [ "Perl", @@ -403,11 +375,13 @@ "Blog", 10 ] - ] + ], + "id" : "021", + "name" : "021" }, { - "id" : "022", "name" : "022", + "id" : "022", "data" : [ [ "Perl", @@ -442,8 +416,6 @@ "name" : "023" }, { - "name" : "024", - "id" : "024", "data" : [ [ "Perl", @@ -457,7 +429,9 @@ "Blog", 11 ] - ] + ], + "id" : "024", + "name" : "024" }, { "data" : [ @@ -474,10 +448,12 @@ 12 ] ], - "name" : "025", - "id" : "025" + "id" : "025", + "name" : "025" }, { + "name" : "026", + "id" : "026", "data" : [ [ "Perl", @@ -491,11 +467,11 @@ "Blog", 10 ] - ], - "id" : "026", - "name" : "026" + ] }, { + "id" : "027", + "name" : "027", "data" : [ [ "Perl", @@ -509,9 +485,7 @@ "Blog", 9 ] - ], - "id" : "027", - "name" : "027" + ] }, { "name" : "028", @@ -550,8 +524,6 @@ ] }, { - "name" : "030", - "id" : "030", "data" : [ [ "Perl", @@ -565,7 +537,9 @@ "Blog", 10 ] - ] + ], + "name" : "030", + "id" : "030" }, { "data" : [ @@ -586,8 +560,6 @@ "name" : "031" }, { - "id" : "032", - "name" : "032", "data" : [ [ "Perl", @@ -601,7 +573,9 @@ "Blog", 10 ] - ] + ], + "name" : "032", + "id" : "032" }, { "name" : "033", @@ -622,8 +596,8 @@ ] }, { - "id" : "034", "name" : "034", + "id" : "034", "data" : [ [ "Perl", @@ -640,6 +614,8 @@ ] }, { + "name" : "035", + "id" : "035", "data" : [ [ "Perl", @@ -653,13 +629,9 @@ "Blog", 9 ] - ], - "name" : "035", - "id" : "035" + ] }, { - "id" : "036", - "name" : "036", "data" : [ [ "Perl", @@ -673,7 +645,9 @@ "Blog", 11 ] - ] + ], + "id" : "036", + "name" : "036" }, { "id" : "037", @@ -694,6 +668,8 @@ ] }, { + "name" : "038", + "id" : "038", "data" : [ [ "Perl", @@ -707,11 +683,11 @@ "Blog", 12 ] - ], - "name" : "038", - "id" : "038" + ] }, { + "name" : "039", + "id" : "039", "data" : [ [ "Perl", @@ -725,11 +701,11 @@ "Blog", 12 ] - ], - "name" : "039", - "id" : "039" + ] }, { + "id" : "040", + "name" : "040", "data" : [ [ "Perl", @@ -743,9 +719,7 @@ "Blog", 10 ] - ], - "id" : "040", - "name" : "040" + ] }, { "data" : [ @@ -766,8 +740,8 @@ "name" : "041" }, { - "name" : "042", "id" : "042", + "name" : "042", "data" : [ [ "Perl", @@ -802,8 +776,6 @@ ] }, { - "id" : "044", |
