diff options
23 files changed, 1462 insertions, 1311 deletions
diff --git a/challenge-146/laurent-rosenfeld/blog.txt b/challenge-146/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..75b6bbfcdc --- /dev/null +++ b/challenge-146/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2022/01/perl-weekly-challenge-146-prime-numbers-and-fraction-tree.html diff --git a/challenge-146/laurent-rosenfeld/julia/ch-2.jl b/challenge-146/laurent-rosenfeld/julia/ch-2.jl new file mode 100644 index 0000000000..65a5ec63df --- /dev/null +++ b/challenge-146/laurent-rosenfeld/julia/ch-2.jl @@ -0,0 +1,11 @@ +function find_parent(num, denom) + return num < denom ? [num, denom - num] : + num > denom ? [num - denom, denom] : + ("Error on node $num $denom"); +end + +for test in [ [5, 2], [2, 5], [3, 4], [3, 5], [1, 2] ] + parent = find_parent(test[1], test[2]) + gd_parent = find_parent(parent[1], parent[2]) + println("Node $test has parent $parent and grand-parent $gd_parent") +end diff --git a/challenge-146/laurent-rosenfeld/perl/ch-1.pl b/challenge-146/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..6d62f8471e --- /dev/null +++ b/challenge-146/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,26 @@ +use strict; +use warnings; +use feature "say"; +use constant MAX => 10_001; + +sub primes { + my $max = shift; + my @primes = (2, 3, 5); + my $count = 3; + my $candidate = $primes[-1]; + while ($count <= $max) { + $candidate += 2; + my $not_prime = 0; + my $sq_cand = sqrt $candidate; + for my $i (@primes) { + $not_prime = 1, last unless $candidate % $i; + last if $i > $sq_cand; + } + next if $not_prime; + push @primes, $candidate; + $count ++; + } + return $primes[$max-1]; +} +my $p = primes(MAX); +say "$p"; diff --git a/challenge-146/laurent-rosenfeld/perl/ch-2.pl b/challenge-146/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..c9b8f20cbe --- /dev/null +++ b/challenge-146/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +use feature "say"; + +# for a node x/y less than 1, parent is x/(y-x) +# for a node x/y larger than 1, parent is (x-y)/x + +sub parent { + my ($num, $denom) = @{$_[0]}; + return ["Error"] if $num == $denom; + return $num < $denom ? [$num, $denom - $num] : [$num - $denom, $denom]; +} + +for my $fraction ([5, 2], [2, 5], [3, 4], [3, 5], [2, 1], [1, 1]) { + die "Invalid input node @$fraction" if $$fraction[0] == $$fraction[1]; + my $parent = parent $fraction; + my $gd_parent = parent $parent; + say "for child @$fraction, parent is @$parent and gd-parent is @$gd_parent"; +} diff --git a/challenge-146/laurent-rosenfeld/python/ch-2.py b/challenge-146/laurent-rosenfeld/python/ch-2.py new file mode 100644 index 0000000000..7120a602a7 --- /dev/null +++ b/challenge-146/laurent-rosenfeld/python/ch-2.py @@ -0,0 +1,10 @@ +# for a node x/y less than 1, parent is x/(y-x) +# for a node x/y larger than 1, parent is (x-y)/x + +def find_parent(num, denom): + return [num, denom - num] if num < denom else [num - denom, denom] + +for test in ([5, 2], [2, 5], [3, 4], [3, 5]): + parent = find_parent(test[0], test[1]) + gd_parent = find_parent(parent[0], parent[1]) + print("Node", test, "has parent", parent, "and grand-parent", gd_parent) diff --git a/challenge-146/laurent-rosenfeld/raku/ch-1.raku b/challenge-146/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..b181fb89cd --- /dev/null +++ b/challenge-146/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,4 @@ +use v6; + +my @primes = grep { .is-prime }, (1, 2, 3, -> $a { $a + 2} ...Inf); +say @primes[10001 - 1]; # Subtract 1 because the array starts at 0 diff --git a/challenge-146/laurent-rosenfeld/raku/ch-2.raku b/challenge-146/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..22976624bc --- /dev/null +++ b/challenge-146/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,12 @@ +use v6; + +# for a node x/y less than 1, parent is x/(y-x) +# for a node x/y larger than 1, parent is (x-y)/x + +sub parent (\num, \denom) { + return num < denom ?? (num, denom - num) !! (num - denom, denom); +} +for (5, 2), (2, 5), (3, 4), (3, 5) -> $fraction { + my $parent = parent |$fraction[0,1]; + my $gd-parent = parent |$parent[0,1]; + say "for child $fraction, parent is $parent and gd-parent is $gd-parent"; diff --git a/challenge-146/laurent-rosenfeld/ring/ch-1.ring b/challenge-146/laurent-rosenfeld/ring/ch-1.ring new file mode 100644 index 0000000000..bd5ecf2178 --- /dev/null +++ b/challenge-146/laurent-rosenfeld/ring/ch-1.ring @@ -0,0 +1,24 @@ +p = primes(10001) +see p + nl + +func primes max + primes = [2, 3, 5] + count = len(primes) + candidate = primes[count] + while count < max + candidate += 2 + is_prime = True + sqrt_cand = sqrt(candidate) + for i in primes + if candidate % i = 0 + is_prime = False + exit + ok + if i > sqrt_cand exit ok + next + if is_prime + add(primes, candidate) + count ++ + ok + end + return primes[max] diff --git a/challenge-146/laurent-rosenfeld/ring/ch-2.ring b/challenge-146/laurent-rosenfeld/ring/ch-2.ring new file mode 100644 index 0000000000..78b9092395 --- /dev/null +++ b/challenge-146/laurent-rosenfeld/ring/ch-2.ring @@ -0,0 +1,21 @@ +# for a node x/y less than 1, parent is x/(y-x) +# for a node x/y larger than 1, parent is (x-y)/x + +for test in [ [5, 2], [2, 5], [3, 4], [3,5], [6, 2], [1, 2] ] + parent = find_parent(test[1], test[2]) + gd_parent = find_parent(parent[1], parent[2]) + see "Node " + to_str(test) + " has parent " + to_str(parent) + + " and grand-parent " + to_str(gd_parent) + nl +next + +func find_parent num, denom + if num < denom + return [num, denom - num] + but denom < num + return [num - denom, denom] + else + return ["Error", ""] + ok + +func to_str input + return "" + input[1] + " " + input[2] diff --git a/stats/pwc-current.json b/stats/pwc-current.json index bf0c57346f..14476c9b09 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,8 +1,157 @@ { + "series" : [ + { + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 146", + "data" : [ + { + "y" : 4, + "name" : "Abigail", + "drilldown" : "Abigail" + }, + { + "drilldown" : "Andrew Shitov", + "name" : "Andrew Shitov", + "y" : 1 + }, + { + "drilldown" : "Andrezgz", + "name" : "Andrezgz", + "y" : 2 + }, + { + "drilldown" : "Arne Sommer", + "name" : "Arne Sommer", + "y" : 5 + }, + { + "y" : 4, + "drilldown" : "Athanasius", + "name" : "Athanasius" + }, + { + "y" : 3, + "drilldown" : "Dave Jacoby", + "name" : "Dave Jacoby" + }, + { + "drilldown" : "E. Choroba", + "name" : "E. Choroba", + "y" : 2 + }, + { + "y" : 2, + "name" : "Feng Chang", + "drilldown" : "Feng Chang" + }, + { + "name" : "Flavio Poletti", + "drilldown" : "Flavio Poletti", + "y" : 6 + }, + { + "drilldown" : "James Smith", + "name" : "James Smith", + "y" : 3 + }, + { + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey", + "y" : 1 + }, + { + "y" : 5, + "name" : "Laurent Rosenfeld", + "drilldown" : "Laurent Rosenfeld" + }, + { + "drilldown" : "Luca Ferrari", + "name" : "Luca Ferrari", + "y" : 6 + }, + { + "y" : 2, + "name" : "Mark Anderson", + "drilldown" : "Mark Anderson" + }, + { + "drilldown" : "Mohammad S Anwar", + "name" : "Mohammad S Anwar", + "y" : 2 + }, + { + "drilldown" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", + "y" : 3 + }, + { + "drilldown" : "Robert DiCicco", + "name" : "Robert DiCicco", + "y" : 2 + }, + { + "y" : 5, + "name" : "Roger Bell_West", + "drilldown" : "Roger Bell_West" + }, + { + "drilldown" : "Simon Green", + "name" : "Simon Green", + "y" : 3 + }, + { + "y" : 2, + "drilldown" : "Simon Proctor", + "name" : "Simon Proctor" + }, + { + "name" : "Ulrich Rieke", + "drilldown" : "Ulrich Rieke", + "y" : 4 + }, + { + "name" : "W. Luis Mochan", + "drilldown" : "W. Luis Mochan", + "y" : 3 + } + ] + } + ], + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 + } + }, + "subtitle" : { + "text" : "[Champions: 22] Last updated at 2022-01-07 09:51:12 GMT" + }, + "legend" : { + "enabled" : 0 + }, + "xAxis" : { + "type" : "category" + }, + "yAxis" : { + "title" : { + "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" : "The Weekly Challenge - 146" + }, "drilldown" : { "series" : [ { - "name" : "Abigail", + "id" : "Abigail", "data" : [ [ "Perl", @@ -13,7 +162,7 @@ 2 ] ], - "id" : "Abigail" + "name" : "Abigail" }, { "data" : [ @@ -22,21 +171,20 @@ 1 ] ], - "id" : "Andrew Shitov", - "name" : "Andrew Shitov" + "name" : "Andrew Shitov", + "id" : "Andrew Shitov" }, { - "name" : "Andrezgz", + "id" : "Andrezgz", "data" : [ [ "Perl", 2 ] ], - "id" : "Andrezgz" + "name" : "Andrezgz" }, { - "id" : "Arne Sommer", "data" : [ [ "Perl", @@ -51,11 +199,12 @@ 1 ] ], - "name" : "Arne Sommer" + "name" : "Arne Sommer", + "id" : "Arne Sommer" }, { - "name" : "Athanasius", "id" : "Athanasius", + "name" : "Athanasius", "data" : [ [ "Perl", @@ -68,7 +217,6 @@ ] }, { - "name" : "Dave Jacoby", "id" : "Dave Jacoby", "data" : [ [ @@ -79,11 +227,12 @@ "Blog", 1 ] - ] + ], + "name" : "Dave Jacoby" }, { - "name" : "E. Choroba", "id" : "E. Choroba", + "name" : "E. Choroba", "data" : [ [ "Perl", @@ -92,17 +241,16 @@ ] }, { + "id" : "Feng Chang", "name" : "Feng Chang", "data" : [ [ "Raku", 2 ] - ], - "id" : "Feng Chang" + ] }, { - "name" : "Flavio Poletti", "id" : "Flavio Poletti", "data" : [ [ @@ -117,10 +265,10 @@ "Blog", 2 ] - ] + ], + "name" : "Flavio Poletti" }, { - "name" : "James Smith", "data" : [ [ "Perl", @@ -131,17 +279,36 @@ 1 ] ], + "name" : "James Smith", "id" : "James Smith" }, { + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey", "data" : [ [ "Perl", 1 ] + ] + }, + { + "id" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] ], - "id" : "Jorg Sommrey", - "name" : "Jorg Sommrey" + "name" : "Laurent Rosenfeld" }, { "name" : "Luca Ferrari", @@ -164,11 +331,11 @@ 2 ] ], - "id" : "Mark Anderson", - "name" : "Mark Anderson" + "name" : "Mark Anderson", + "id" : "Mark Anderson" }, { - "name" : "Mohammad S Anwar", + "id" : "Mohammad S Anwar", "data" : [ [ "Perl", @@ -179,9 +346,10 @@ 1 ] ], - "id" : "Mohammad S Anwar" + "name" : "Mohammad S Anwar" }, { + "name" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -192,20 +360,20 @@ 1 ] ], - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "id" : "Peter Campbell Smith" }, { - "name" : "Robert DiCicco", + "id" : "Robert DiCicco", "data" : [ [ "Perl", 2 ] ], - "id" : "Robert DiCicco" + "name" : "Robert DiCicco" }, { + "id" : "Roger Bell_West", "name" : "Roger Bell_West", "data" : [ [ @@ -220,11 +388,9 @@ "Blog", 1 ] - ], - "id" : "Roger Bell_West" + ] }, { - "id" : "Simon Green", "data" : [ [ "Perl", @@ -235,11 +401,12 @@ 1 ] ], - "name" : "Simon Green" + "name" : "Simon Green", + "id" : "Simon Green" }, { - "name" : "Simon Proctor", "id" : "Simon Proctor", + "name" : "Simon Proctor", "data" : [ [ "Raku", @@ -248,7 +415,6 @@ ] }, { - "id" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -259,9 +425,11 @@ 2 ] ], - "name" : "Ulrich Rieke" + "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke" }, { + "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -272,156 +440,11 @@ 1 ] ], - "id" : "W. Luis Mochan", "name" : "W. Luis Mochan" } ] }, - "legend" : { - "enabled" : 0 - }, - "series" : [ - { - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 146", - "data" : [ - { - "y" : 4, - "name" : "Abigail", - "drilldown" : "Abigail" - }, - { - "drilldown" : "Andrew Shitov", - "y" : 1, - "name" : "Andrew Shitov" - }, - { - "y" : 2, - "name" : "Andrezgz", - "drilldown" : "Andrezgz" - }, - { - "drilldown" : "Arne Sommer", - "y" : 5, - "name" : "Arne Sommer" - }, - { - "name" : "Athanasius", - "y" : 4, - "drilldown" : "Athanasius" - }, - { - "y" : 3, - "name" : "Dave Jacoby", - "drilldown" : "Dave Jacoby" - }, - { - "drilldown" : "E. Choroba", - "name" : "E. Choroba", - "y" : 2 - }, - { - "drilldown" : "Feng Chang", - "name" : "Feng Chang", - "y" : 2 - }, - { - "drilldown" : "Flavio Poletti", - "y" : 6, - "name" : "Flavio Poletti" - }, - { - "drilldown" : "James Smith", - "name" : "James Smith", - "y" : 3 - }, - { - "name" : "Jorg Sommrey", - "y" : 1, - "drilldown" : "Jorg Sommrey" - }, - { - "name" : "Luca Ferrari", - "y" : 6, - "drilldown" : "Luca Ferrari" - }, - { - "y" : 2, - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson" - }, - { - "name" : "Mohammad S Anwar", - "y" : 2, - "drilldown" : "Mohammad S Anwar" - }, - { - "drilldown" : "Peter Campbell Smith", - "y" : 3, - "name" : "Peter Campbell Smith" - }, - { - "drilldown" : "Robert DiCicco", - "name" : "Robert DiCicco", - "y" : 2 - }, - { - "name" : "Roger Bell_West", - "y" : 5, - "drilldown" : "Roger Bell_West" - }, - { - "drilldown" : "Simon Green", - "y" : 3, - "name" : "Simon Green" - }, - { - "drilldown" : "Simon Proctor", - "y" : 2, - "name" : "Simon Proctor" - }, - { - "y" : 4, - "name" : "Ulrich Rieke", - "drilldown" : "Ulrich Rieke" - }, - { - "drilldown" : "W. Luis Mochan", - "y" : 3, - "name" : "W. Luis Mochan" - } - ] - } - ], - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } - }, - "subtitle" : { - "text" : "[Champions: 21] Last updated at 2022-01-07 09:14:31 GMT" - }, - "title" : { - "text" : "The Weekly Challenge - 146" - }, "chart" : { "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "xAxis" : { - "type" : "category" - }, - "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/>" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 6883874036..3b49d55777 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,63 +1,63 @@ { - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, "xAxis" : { + "type" : "category", "labels" : { "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" } - }, - "type" : "category" + } + }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2021]" }, "yAxis" : { + "min" : 0, "title" : { "text" : null - }, - "min" : 0 + } + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" }, "chart" : { "type" : "column" }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2021]" - }, "series" : [ { + "dataLabels" : { + "format" : "{point.y:.0f}", + "y" : 10, + "rotation" : -90, + "color" : "#FFFFFF", + "align" : "right", + "enabled" : "true", + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + } + }, "name" : "Contributions", "data" : [ [ "Blog", - 2163 + 2164 ], [ "Perl", - 7037 + 7039 ], [ "Raku", - 4239 + 4241 ] - ], - "dataLabels" : { - "format" : "{point.y:.0f}", - "enabled" : "true", - "align" : "right", - "y" : 10, - "color" : "#FFFFFF", - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, - "rotation" : -90 - } + ] } ], + "subtitle" : { + "text" : "Last updated at 2022-01-07 09:51:12 GMT" + }, "legend" : { "enabled" : "false" - }, - "subtitle" : { - "text" : "Last updated at 2022-01-07 09:14:31 GMT" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 54c106d500..01761c276b 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,28 +1,27 @@ { - "chart" : { - "type" : "column" - }, "title" : { "text" : "The Weekly Challenge Language" }, "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" + "followPointer" : "true", + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, + "xAxis" : { + "type" : "category" + }, + "chart" : { + "type" : "column" + }, "drilldown" : { "series" : [ { "name" : "001", - "id" : "001", "data" : [ [ "Perl", @@ -36,7 +35,8 @@ "Blog", 11 ] - ] + ], + "id" : "001" }, { "data" : [ @@ -53,10 +53,11 @@ 10 ] ], - "id" : "002", - "name" : "002" + "name" : "002", + "id" : "002" }, { + "id" : "003", "name" : "003", "data" : [ [ @@ -71,11 +72,9 @@ "Blog", 9 ] - ], - "id" : "003" + ] }, { - "name" : "004", "id" : "004", "data" : [ [ @@ -90,9 +89,11 @@ "Blog", 10 ] - ] + ], + "name" : "004" }, { + "name" : "005", "data" : [ [ "Perl", @@ -107,8 +108,7 @@ 12 ] ], - "id" : "005", - "name" : "005" + "id" : "005" }, { "data" : [ @@ -125,10 +125,11 @@ 7 ] ], - "id" : "006", - "name" : "006" + "name" : "006", + "id" : "006" }, { + "name" : "007", "data" : [ [ "Perl", @@ -143,8 +144,7 @@ 10 ] ], - "id" : "007", - "name" : "007" + "id" : "007" }, { "name" : "008", @@ -165,7 +165,6 @@ "id" : "008" }, { - "name" : "009", "id" : "009", "data" : [ [ @@ -180,7 +179,8 @@ "Blog", 13 ] - ] + ], + "name" : "009" }, { "data" : [ @@ -197,11 +197,10 @@ 11 ] ], - "id" : "010", - "name" : "010" + "name" : "010", + "id" : "010" }, { - "id" : "011", "data" : [ [ "Perl", @@ -216,10 +215,12 @@ 10 ] ], - "name" : "011" + "name" : "011", + "id" : "011" }, { "id" : "012", + "name" : "012", |
