diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-09-01 10:11:43 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-09-01 10:11:43 +0100 |
| commit | 38e52082d4226929ed3a490c62ebe3e4c998ea66 (patch) | |
| tree | 170e710697a35686abc67ab456ea015ffaa86e20 | |
| parent | ce1946f8231d4c94491c4cef73cb9567ff6b3ed1 (diff) | |
| download | perlweeklychallenge-club-38e52082d4226929ed3a490c62ebe3e4c998ea66.tar.gz perlweeklychallenge-club-38e52082d4226929ed3a490c62ebe3e4c998ea66.tar.bz2 perlweeklychallenge-club-38e52082d4226929ed3a490c62ebe3e4c998ea66.zip | |
- Added solutions by Colin Crain.
| -rw-r--r-- | challenge-023/colin-crain/README | 1 | ||||
| -rw-r--r-- | challenge-023/colin-crain/perl5/ch-1.pl | 58 | ||||
| -rw-r--r-- | challenge-023/colin-crain/perl5/ch-2.pl | 74 | ||||
| -rw-r--r-- | challenge-023/colin-crain/perl5/ch-3.pl | 69 | ||||
| -rw-r--r-- | members.json | 1 | ||||
| -rw-r--r-- | stats/pwc-current.json | 175 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 72 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 368 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 490 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 130 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 56 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 270 |
14 files changed, 1041 insertions, 815 deletions
diff --git a/challenge-023/colin-crain/README b/challenge-023/colin-crain/README new file mode 100644 index 0000000000..2a5d87e97d --- /dev/null +++ b/challenge-023/colin-crain/README @@ -0,0 +1 @@ +Solutions by Colin Crain. diff --git a/challenge-023/colin-crain/perl5/ch-1.pl b/challenge-023/colin-crain/perl5/ch-1.pl new file mode 100644 index 0000000000..b7cc06e831 --- /dev/null +++ b/challenge-023/colin-crain/perl5/ch-1.pl @@ -0,0 +1,58 @@ +#! /opt/local/bin/perl +# +# nth_order_forward_difference.pl +# +# prints nth order forward difference series. +# +# usage - first argument order depth of difference +# further arguments represent the series to be evaluated +# example: 2 5 9 2 8 1 7 will produce the 2nd order difference on the sequence (5, 9, 2, 8, 1, 7) +} +# +# 2019 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + +use warnings; +use strict; +use feature ":5.26"; + +## ## ## ## ## MAIN + +my ($depth, @series) = @ARGV; + +if (! $depth) { + die "usage - first argument order depth of difference\n", + "further arguments represent the series to be evaluated\n", + "example: 2 5 9 2 8 1 7 will produce the 2nd order difference on the sequence (5, 9, 2, 8, 1, 7)\n"; +} + +if (scalar @series - 1 < $depth) { + die "cannot compute depth $depth difference series:\n", + "insufficient elements in series \(", + (join ', ', @series), "\)\n"; +} + +while ($depth) { + + my @differences = (); + +## uncomment to produce a nice verbose representation of intermediate states +# my $format = join ', ', map {"%6d"} @series; +# printf "$format\n", @series; + + ## ratchet through the list creating a new list of differences between + ## an element and the next forward + while (scalar @series > 1) { + my $first = shift @series; + my $second = $series[0]; + push @differences, ($second - $first); + } + + $depth--; + @series = @differences; + +} + +say (join ', ', @series); + + diff --git a/challenge-023/colin-crain/perl5/ch-2.pl b/challenge-023/colin-crain/perl5/ch-2.pl new file mode 100644 index 0000000000..c30ceb9625 --- /dev/null +++ b/challenge-023/colin-crain/perl5/ch-2.pl @@ -0,0 +1,74 @@ +#! /opt/local/bin/perl +# +# prime_decomposition.pl +# +# prints Prime Decomposition of a given number, given as an argument +# +# +# 2019 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +use warnings; +use strict; +use feature ":5.26"; + +## ## ## ## ## MAIN + +my $target = shift @ARGV; +my @decomp = decompose( $target ); +say (join ', ', @decomp); + +## ## ## ## ## SUBS + +sub decompose { +## given a number, +## returns an array list of prime decomposition factors of the number + my $num = shift; + my @decomp; + my $prime = 2; + my $primelist = [$prime]; + + while ( $prime <= $num ) { + while ($num % $prime == 0) { + $num = $num / $prime; + push @decomp, $prime; + } + $prime = get_next_prime($primelist); + } + + return @decomp; + +} + +sub get_next_prime { +## given a listref of all primes up until a certain point, +## adds next prime to the list and returns the prime + + my $primelist = shift; + + ## assign the last prime recorded + 1 as the new candidate + my $candidate = $primelist->[scalar $primelist->@* - 1] + 1; + + ## index through the prime list checking for divisability; if found + ## augment and restart the test. + ## if the test value exceeds the squareroot of the candidate, the candidate + ## is prime. Put it on the list and return the candidate. + ## yes it's an infinite loop but there will always be another prime, right? + ## right? + for (my $i = 0; my $test = $primelist->[$i]; $i++) { + my $root = int(sqrt($candidate)); + if ($test > $root) { + push $primelist->@*, $candidate; + return $candidate; + } + + if ($candidate % $test == 0) { + $i = -1; + $candidate++; + next; + } + } + +} diff --git a/challenge-023/colin-crain/perl5/ch-3.pl b/challenge-023/colin-crain/perl5/ch-3.pl new file mode 100644 index 0000000000..9080a38838 --- /dev/null +++ b/challenge-023/colin-crain/perl5/ch-3.pl @@ -0,0 +1,69 @@ +#! /opt/local/bin/perl +# +# poem_api_2.pl +# +# access the random poem api at https://www.poemist.com/api/v1/randompoems +# decode the JSON and print to STDOUT +# +# 2019 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + +use LWP::UserAgent; +use JSON::XS qw( decode_json ); + +use warnings; +use strict; +use diagnostics; +use feature ":5.26"; + +binmode STDOUT, ':utf8'; + +## ## ## ## ## MAIN + +## Create a user agent object +my $ua = LWP::UserAgent->new( + ssl_opts => { + verify_hostname => 1, + } +); +$ua->agent("random_poem_api/1.0"); + +## Create a request +my $req = HTTP::Request->new( GET => 'https://www.poemist.com/api/v1/randompoems' ); +$req->header( 'Accept' => 'application/json'); + +## Pass request to the user agent and get a response back +my $res = $ua->request($req); + +## Check the outcome of the response +if (! $res->is_success) { + die "there was bad response: ", $res->status_line, "\n"; +} + +## decode the JSON data +my $data = decode_json $res->content; + +## the decoded data is an array ref of hash refs, each with keys: +## {content} +## {title} +## {url} +## {poet}->{name} +## {poet}->{url} + +## output to STDOUT +foreach my $poem ( $data->@* ) { + ## there are weird database glitches that need to be worked around + ## rarely some poems appear to have no content, or no title. Some Arabic poems in particular. + ## Rather than fail we'll simply silently skip these. + next if ( ! $poem->{title} || ! $poem->{poet}->{name} || ! $poem->{content} || ! $poem->{url} ); + + say $poem->{title}; + say "by $poem->{poet}->{name}"; + say ""; + say $poem->{content}; + say ""; + say "url: ", $poem->{url}; + say "\n----------\n"; +} + + diff --git a/members.json b/members.json index 495ea73d0f..ec92204f0c 100644 --- a/members.json +++ b/members.json @@ -17,6 +17,7 @@ "bob-kleemann" : "Bob Kleemann", "bruno-ramos" : "Bruno Ramos", "cliveholloway" : "Clive Holloway", + "colin-crain" : "Colin Crain", "daniel-mantovani" : "Daniel Mantovani", "daniel-mita" : "Daniel Mita", "dave-cross" : "Dave Cross", diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 71820aca9b..1ac5d94b01 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -4,48 +4,20 @@ "text" : "Total Solutions" } }, - "tooltip" : { - "followPointer" : 1, - "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/>" - }, - "title" : { - "text" : "Perl Weekly Challenge - 023" - }, - "legend" : { - "enabled" : 0 - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } - } - }, - "subtitle" : { - "text" : "[Champions: 18] Last updated at 2019-09-01 08:53:42 GMT" - }, - "xAxis" : { - "type" : "category" - }, - "chart" : { - "type" : "column" - }, "drilldown" : { "series" : [ { - "name" : "Andrezgz", + "id" : "Andrezgz", "data" : [ [ "Perl 5", 3 ] ], - "id" : "Andrezgz" + "name" : "Andrezgz" }, { + "id" : "Arne Sommer", "data" : [ [ "Perl 5", @@ -60,28 +32,37 @@ 1 ] ], - "name" : "Arne Sommer", - "id" : "Arne Sommer" + "name" : "Arne Sommer" }, { + "id" : "Colin Crain", + "data" : [ + [ + "Perl 5", + 3 + ] + ], + "name" : "Colin Crain" + }, + { + "id" : "Daniel Mantovani", "data" : [ [ "Perl 5", 2 ] ], - "name" : "Daniel Mantovani", - "id" : "Daniel Mantovani" + "name" : "Daniel Mantovani" }, { - "id" : "Duane Powell", + "name" : "Duane Powell", "data" : [ [ "Perl 5", 2 ] ], - "name" : "Duane Powell" + "id" : "Duane Powell" }, { "data" : [ @@ -94,22 +75,21 @@ 1 ] ], - "name" : "E. Choroba", - "id" : "E. Choroba" + "id" : "E. Choroba", + "name" : "E. Choroba" }, { + "name" : "Guillermo Ramos", "id" : "Guillermo Ramos", "data" : [ [ "Perl 5", 3 ] - ], - "name" : "Guillermo Ramos" + ] }, { "id" : "Joelle Maslak", - "name" : "Joelle Maslak", "data" : [ [ "Perl 5", @@ -119,17 +99,18 @@ "Perl 6", 3 ] - ] + ], + "name" : "Joelle Maslak" }, { "id" : "Kevin Colyer", - "name" : "Kevin Colyer", "data" : [ [ "Perl 6", 2 ] - ] + ], + "name" : "Kevin Colyer" }, { "name" : "Laurent Rosenfeld", @@ -151,25 +132,27 @@ }, { "name" : "Mark Anderson", + "id" : "Mark Anderson", "data" : [ [ "Perl 5", 3 ] - ], - "id" : "Mark Anderson" + ] }, { - "id" : "Noud", "name" : "Noud", "data" : [ [ "Perl 6", 2 ] - ] + ], + "id" : "Noud" }, { + "name" : "Randy Lauen", + "id" : "Randy Lauen", "data" : [ [ "Perl 5", @@ -179,13 +162,9 @@ "Perl 6", 3 ] - ], - "name" : "Randy Lauen", - "id" : "Randy Lauen" + ] }, { - "id" : "Roger Bell West", - "name" : "Roger Bell West", "data" : [ [ "Perl 5", @@ -199,7 +178,9 @@ "Blog", 1 ] - ] + ], + "id" : "Roger Bell West", + "name" : "Roger Bell West" }, { "data" : [ @@ -212,18 +193,18 @@ 2 ] ], - "name" : "Ruben Westerberg", - "id" : "Ruben Westerberg" + "id" : "Ruben Westerberg", + "name" : "Ruben Westerberg" }, { + "name" : "Simon Proctor", + "id" : "Simon Proctor", "data" : [ [ "Perl 6", 2 ] - ], - "name" : "Simon Proctor", - "id" : "Simon Proctor" + ] }, { "id" : "Steven Wilson", @@ -260,20 +241,23 @@ 1 ] ], - "name" : "Yet Ebreo", - "id" : "Yet Ebreo" + "id" : "Yet Ebreo", + "name" : "Yet Ebreo" } ] }, + "xAxis" : { + "type" : "category" + }, "series" : [ { - "colorByPoint" : 1, "name" : "Perl Weekly Challenge - 023", + "colorByPoint" : 1, "data" : [ { + "name" : "Andrezgz", "drilldown" : "Andrezgz", - "y" : 3, - "name" : "Andrezgz" + "y" : 3 }, { "drilldown" : "Arne Sommer", @@ -281,6 +265,11 @@ "name" : "Arne Sommer" }, { + "name" : "Colin Crain", + "y" : 3, + "drilldown" : "Colin Crain" + }, + { "y" : 2, "drilldown" : "Daniel Mantovani", "name" : "Daniel Mantovani" @@ -296,9 +285,9 @@ "name" : "E. Choroba" }, { - "name" : "Guillermo Ramos", "drilldown" : "Guillermo Ramos", - "y" : 3 + "y" : 3, + "name" : "Guillermo Ramos" }, { "name" : "Joelle Maslak", @@ -306,9 +295,9 @@ "drilldown" : "Joelle Maslak" }, { - "y" : 2, + "name" : "Kevin Colyer", "drilldown" : "Kevin Colyer", - "name" : "Kevin Colyer" + "y" : 2 }, { "drilldown" : "Laurent Rosenfeld", @@ -316,13 +305,13 @@ "name" : "Laurent Rosenfeld" }, { - "name" : "Mark Anderson", + "drilldown" : "Mark Anderson", "y" : 3, - "drilldown" : "Mark Anderson" + "name" : "Mark Anderson" }, { - "y" : 2, "drilldown" : "Noud", + "y" : 2, "name" : "Noud" }, { @@ -336,9 +325,9 @@ "name" : "Roger Bell West" }, { + "name" : "Ruben Westerberg", "y" : 4, - "drilldown" : "Ruben Westerberg", - "name" : "Ruben Westerberg" + "drilldown" : "Ruben Westerberg" }, { "drilldown" : "Simon Proctor", @@ -346,21 +335,47 @@ "name" : "Simon Proctor" }, { - "y" : 1, "drilldown" : "Steven Wilson", + "y" : 1, "name" : "Steven Wilson" }, { - "name" : "Walt Mankowski", "drilldown" : "Walt Mankowski", - "y" : 2 + "y" : 2, + "name" : "Walt Mankowski" }, { + "name" : "Yet Ebreo", "y" : 7, - "drilldown" : "Yet Ebreo", - "name" : "Yet Ebreo" + "drilldown" : "Yet Ebreo" } ] } - ] + ], + "chart" : { + "type" : "column" + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 + } + }, + "subtitle" : { + "text" : "[Champions: 19] Last updated at 2019-09-01 09:11:19 GMT" + }, + "tooltip" : { + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" + }, + "legend" : { + "enabled" : 0 + }, + "title" : { + "text" : "Perl Weekly Challenge - 023" + } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 0855ded770..c9b48ba0ef 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,6 +1,40 @@ { + "chart" : { + "type" : "column" + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, + "subtitle" : { + "text" : "Last updated at 2019-09-01 09:11:35 GMT" + }, + "xAxis" : { + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + }, + "type" : "category" + }, + "title" : { + "text" : "Perl Weekly Challenge Contributions - 2019" + }, "series" : [ { + "dataLabels" : { + "enabled" : "true", + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + }, + "format" : "{point.y:.0f}", + "align" : "right", + "color" : "#FFFFFF", + "y" : 10, + "rotation" : -90 + }, + "name" : "Contributions", "data" : [ [ "Blog", @@ -8,56 +42,22 @@ ], [ "Perl 5", - 956 + 959 ], [ "Perl 6", 576 ] - ], - "dataLabels" : { - "align" : "right", - "y" : 10, - "rotation" : -90, - "color" : "#FFFFFF", - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, - "format" : "{point.y:.0f}", - "enabled" : "true" - }, - "name" : "Contributions" + ] } ], - "title" : { - "text" : "Perl Weekly Challenge Contributions - 2019" - }, - "subtitle" : { - "text" : "Last updated at 2019-09-01 08:54:22 GMT" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, "legend" : { "enabled" : "false" }, - "xAxis" : { - "type" : "category", - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } - } - }, "yAxis" : { "title" : { "text" : null }, "min" : 0 - }, - "chart" : { - "type" : "column" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index f77c42105c..98dc20843f 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,137 +1,31 @@ { - "series" : [ - { - "colorByPoint" : "true", - "name" : "Perl Weekly Challenge Languages", - "data" : [ - { - "name" : "#001", - "drilldown" : "001", - "y" : 132 - }, - { - "name" : "#002", - "drilldown" : "002", - "y" : 104 - }, - { - "name" : "#003", - "y" : 66, - "drilldown" : "003" - }, - { - "y" : 86, - "drilldown" : "004", - "name" : "#004" - }, - { - "name" : "#005", - "drilldown" : "005", - "y" : 66 - }, - { - "y" : 47, - "drilldown" : "006", - "name" : "#006" - }, - { - "y" : 55, - "drilldown" : "007", - "name" : "#007" - }, - { - "name" : "#008", - "drilldown" : "008", - "y" : 68 - }, - { - "name" : "#009", - "drilldown" : "009", - "y" : 66 - }, - { - "drilldown" : "010", - "y" : 59, - "name" : "#010" - }, - { - "y" : 78, - "drilldown" : "011", - "name" : "#011" - }, - { - "name" : "#012", - "y" : 82, - "drilldown" : "012" - }, - { - "name" : "#013", - "y" : 75, - "drilldown" : "013" - }, - { - "drilldown" : "014", - "y" : 95, - "name" : "#014" - }, - { - "name" : "#015", - "drilldown" : "015", - "y" : 91 - }, - { - "name" : "#016", - "drilldown" : "016", - "y" : 65 - }, - { - "name" : "#017", - "drilldown" : "017", - "y" : 78 - }, - { - "name" : "#018", - "y" : 76, - "drilldown" : "018" - }, - { - "y" : 95, - "drilldown" : "019", - "name" : "#019" - }, - { - "y" : 95, - "drilldown" : "020", - "name" : "#020" - }, - { - "name" : "#021", - "drilldown" : "021", - "y" : 66 - }, - { - "y" : 60, - "drilldown" : "022", - "name" : "#022" - }, - { - "drilldown" : "023", - "y" : 63, - "name" : "#023" - } - ] - } - ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2019-09-01 08:54:22 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2019-09-01 09:11:35 GMT" }, "tooltip" : { + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", "headerFormat" : "<span style=\"font-size:11px\"></span>", - "followPointer" : "true", - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" + "followPointer" : "true" }, - "title" : { - "text" : "Perl Weekly Challenge Language" + "chart" : { + "type" : "column" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "legend" : { + "enabled" : "false" }, "drilldown" : { "series" : [ @@ -154,7 +48,6 @@ "name" : "001" }, { - "id" : "002", "data" : [ [ "Perl 5", @@ -169,9 +62,11 @@ 9 ] ], - "name" : "002" + "name" : "002", + "id" : "002" }, { + "id" : "003", "data" : [ [ "Perl 5", @@ -186,10 +81,10 @@ 8 ] ], - "name" : "003", - "id" : "003" + "name" : "003" }, { + "id" : "004", "data" : [ [ "Perl 5", @@ -204,10 +99,10 @@ 9 ] ], - "name" : "004", - "id" : "004" + "name" : "004" }, { + "name" : "005", "data" : [ [ "Perl 5", @@ -222,10 +117,11 @@ 11 ] ], - "name" : "005", "id" : "005" }, { + "id" : "006", + "name" : "006", "data" : [ [ "Perl 5", @@ -239,11 +135,10 @@ "Blog", 6 ] - ], - "name" : "006", - "id" : "006" + ] }, { + "name" : "007", "data" : [ [ "Perl 5", @@ -258,11 +153,9 @@ 9 ] ], - "name" : "007", "id" : "007" }, { - "id" : "008", "name" : "008", "data" : [ [ @@ -277,10 +170,10 @@ "Blog", 10 ] - ] + ], + "id" : "008" }, { - "name" : "009", "data" : [ [ "Perl 5", @@ -295,9 +188,11 @@ 12 ] ], + "name" : "009", "id" : "009" }, { + "id" : "010", "data" : [ [ "Perl 5", @@ -312,10 +207,11 @@ 10 ] ], - "name" : "010", - "id" : "010" + "name" : "010" }, { + "id" : "011", + "name" : "011", "data" : [ [ "Perl 5", @@ -329,9 +225,7 @@ "Blog", 9 ] - ], - "name" : "011", - "id" : "011" + ] }, { "id" : "012", @@ -353,7 +247,6 @@ }, { "id" : "013", - "name" : "013", "data" : [ [ "Perl 5", @@ -367,7 +260,8 @@ "Blog", 12 ] - ] + ], + "name" : "013" }, { "id" : "014", @@ -388,6 +282,8 @@ "name" : "014" }, { + "id" : "015", + "name" : "015", "data" : [ [ "Perl 5", @@ -401,11 +297,10 @@ "Blog", 13 ] - ], - "name" : "015", - "id" : "015" + ] }, { + "id" : "016", "data" : [ [ "Perl 5", @@ -420,10 +315,10 @@ 11 ] ], - "name" : "016", - "id" : "016" + "name" : "016" }, { + "id" : "017", "data" : [ [ "Perl 5", @@ -438,11 +333,10 @@ 11 ] ], - "name" : "017", - "id" : "017" + "name" : "017" }, { - "name" : "018", + "id" : "018", "data" : [ [ "Perl 5", @@ -457,10 +351,11 @@ |
