diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-01-21 07:26:32 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-01-21 07:26:32 +0000 |
| commit | 3d86058368a008d95843e98cbbfddaf64b8c63bd (patch) | |
| tree | f489fbdd0d65669b15f6848ec8f783acbc9d8ca5 | |
| parent | 07a74309ecd5a7d8bb1da5f3bbe6773568504d37 (diff) | |
| parent | 6dbc3a09469ff878dd9d6f677ba6dbde38224942 (diff) | |
| download | perlweeklychallenge-club-3d86058368a008d95843e98cbbfddaf64b8c63bd.tar.gz perlweeklychallenge-club-3d86058368a008d95843e98cbbfddaf64b8c63bd.tar.bz2 perlweeklychallenge-club-3d86058368a008d95843e98cbbfddaf64b8c63bd.zip | |
Merge remote-tracking branch 'upstream/master'
27 files changed, 2291 insertions, 1912 deletions
diff --git a/challenge-148/colin-crain/blog.txt b/challenge-148/colin-crain/blog.txt new file mode 100644 index 0000000000..ec46c0edd7 --- /dev/null +++ b/challenge-148/colin-crain/blog.txt @@ -0,0 +1 @@ +https://colincrain.com/2022/01/19/numrs-without-th-lttr/ diff --git a/challenge-148/luca-ferrari/blog-1.txt b/challenge-148/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..15a54284d3 --- /dev/null +++ b/challenge-148/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task1 diff --git a/challenge-148/luca-ferrari/blog-2.txt b/challenge-148/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..0b026a41b4 --- /dev/null +++ b/challenge-148/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task2 diff --git a/challenge-148/luca-ferrari/blog-3.txt b/challenge-148/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..4f5dffef8a --- /dev/null +++ b/challenge-148/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task1pg diff --git a/challenge-148/luca-ferrari/blog-4.txt b/challenge-148/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..eda8245158 --- /dev/null +++ b/challenge-148/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task2pg diff --git a/challenge-148/luca-ferrari/postgresql/ch-1.sql b/challenge-148/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..a1782662de --- /dev/null +++ b/challenge-148/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,18 @@ + SELECT v + FROM generate_series( 1, 10 ) v + WHERE + v IN ( 2, 4, 6 ) + + UNION + + SELECT v + FROM generate_series( 11, 19 ) v + WHERE v IN ( 12 ) + + UNION + + SELECT v + FROM generate_series( 20, 100 ) v + WHERE + v % 10 IN ( 2, 4, 6 ) + AND ( v / 10 )::int IN ( 3, 4, 5, 6 ); diff --git a/challenge-148/luca-ferrari/postgresql/ch-2.sql b/challenge-148/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..5d178955a1 --- /dev/null +++ b/challenge-148/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,31 @@ +WITH RECURSIVE +triplets AS +( + SELECT a::numeric, b::numeric, c::numeric + FROM generate_series( 1, 30 ) a + , generate_series( 1, 30 ) b + , generate_series( 1, 30 ) c + ORDER BY a, b, c +) +, cardano_sum AS +( + SELECT a, b, c, + ( a + b * sqrt( c ) ) AS l + ,( a - b * sqrt( c ) ) AS r + FROM triplets +) +, cardano AS +( + SELECT a, b, c, l, r + , CASE WHEN l < 0 THEN -1 ELSE 1 END * pow( abs( l )::numeric, 1/3::numeric ) + + CASE WHEN r < 0 THEN -1 ELSE 1 END * pow( abs( r )::numeric, 1/3::numeric ) + AS triplet_sum + FROM cardano_sum +) + +SELECT * +FROM cardano +WHERE +abs( 1 - triplet_sum::numeric ) <= 0.0000000001 +LIMIT 5 +; diff --git a/challenge-148/luca-ferrari/raku/ch-1.p6 b/challenge-148/luca-ferrari/raku/ch-1.p6 new file mode 100755 index 0000000000..615f92f91f --- /dev/null +++ b/challenge-148/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,17 @@ +#!raku + + + + + +sub MAIN() { + + my @eban-units = 2, 4, 6; + my @eban-teens = 12; + my @eban-tens = 3, 4, 5, 6; + + $_.say if @eban-units.grep( $_ ) for 1 .. 10; + $_.say if @eban-teens.grep( $_ ) for 11 .. 19; + $_.say if @eban-tens.grep( ( $_ / 10 ).Int ) && @eban-units.grep( $_ % 10 ) for 20 .. 100; + +} diff --git a/challenge-148/luca-ferrari/raku/ch-2.p6 b/challenge-148/luca-ferrari/raku/ch-2.p6 new file mode 100755 index 0000000000..453adc5583 --- /dev/null +++ b/challenge-148/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,28 @@ +#!raku + +multi sub is-cardano-triplet( $a, $b, $c ) { + + my $left = .sign * .abs**( 1 / 3 ) given ( $a + $b * $c.sqrt ); + my $right = .sign * .abs**( 1 / 3 ) given ( $a - $b * $c.sqrt ); + return 1 =~= ( $left + $right ); +} + + +multi sub is-cardano-triplet( @triplet ) { + return is-cardano-triplet( @triplet[ 0 ], @triplet[ 1 ], @triplet[ 2 ] ); +} + +sub MAIN( Int $limit = 5 ) { + my @triplets = lazy gather { + for 1 .. Inf -> $a { + for 1 ..^ $a -> $b { + for 1 ..^ $b -> $c { + $_.take if is-cardano-triplet( $_ ) for ( $a, $b, $c ).permutations; + + } + } + } + }; + + @triplets[ 0 .. $limit ].join( "\n" ).say; +} diff --git a/challenge-148/mattneleigh/perl/ch-1.pl b/challenge-148/mattneleigh/perl/ch-1.pl new file mode 100755 index 0000000000..d3bea6ecc2 --- /dev/null +++ b/challenge-148/mattneleigh/perl/ch-1.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use English; + +################################################################################ +# Begin main execution +################################################################################ + +# Tens-place and ones-place numbers that do +# not have an 'e' in them; numbers from +# sixty six to one hundred all have an 'e' +# so just use a limited subset of digits +my @tens = ( 0, 3, 4, 5, 6 ); +my @ones = ( 0, 2, 4, 6 ); +my @ebans; +my $tens_digit; +my $ones_digit; + +# Loop over the tens place digits +foreach $tens_digit (@tens){ + # Loop over the ones place digits + foreach $ones_digit (@ones){ + if($tens_digit){ + # Tens digit is not zero... + push(@ebans, $tens_digit . $ones_digit); + } else{ + # Tens digit is zero... + push(@ebans, $ones_digit) if($ones_digit); + } + } +} + +print("\nThe Eban numbers below 100 are:\n"); +print(join(", ", @ebans), "\n\n"); + +exit(0); +################################################################################ +# End main execution; subroutines follow +################################################################################ + + + diff --git a/challenge-148/mattneleigh/perl/ch-2.pl b/challenge-148/mattneleigh/perl/ch-2.pl new file mode 100755 index 0000000000..36baaa45bd --- /dev/null +++ b/challenge-148/mattneleigh/perl/ch-2.pl @@ -0,0 +1,130 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use English; + +################################################################################ +# Begin main execution +################################################################################ + +my $count = 5; +my @cardanos; + +@cardanos = calculate_first_cardano_triplets($count); + +printf("\nThe first %d Cardano Triplets are:\n", scalar(@cardanos)); +foreach(@cardanos){ + printf(" (%s)\n", join(", ", @{$_})); +} +print("\n"); + + +exit(0); +################################################################################ +# End main execution; subroutines follow +################################################################################ + + + +################################################################################ +# Find a specified number of the first Cardano Triplets, numbers (A, B, C) that +# meet specified parameters (see link below) +# Takes two arguments: +# * The number of Triplets to find; if this number is zero (0), ALL Cardano +# Triplets whose members' sum is less than or equal to the maximum sum value +# (see below) will be found; if there aren't that many triplets within the +# search range, the returned list (see farther below) will be shorter than +# specified but will contain all Triplets within the range +# * The maximum sum of A, B, and C up to which we'll search for Triplets; if +# this argument is omitted or is false a default of 1000 will be used +# Returns: +# * A list of refs to the Cardano Triplets found, e.g.: +# ( +# [ 2, 1, 5 ], +# [ 5, 1, 52 ], +# [ 5, 2, 13 ], +# ... +# ) +# NOTES: Cardano Triplets are described here: +# https://projecteuler.net/problem=251 +# Which particular triplets you get will depend on the value of the maximum +# sum. +################################################################################ +sub calculate_first_cardano_triplets{ + my $count = int(shift()); + my $max = shift(); + + my @cardanos = (); + my $a; + my $b; + my $c; + + if(defined($max) && $max){ + $max = int($max); + } else{ + $max = 1000; + } + + # Traditionally this is done with the + # variables adding up to some + # particular maximum value... + for($a=1; $a<=($max - 2); $a++){ + for($b=1; $b<=($max - $a - 1); $b++){ + for($c=1; $c<=($max - $a - $b); $c++){ + my $b_sqrt_c = $b * sqrt($c); + + # The calculated value should be zero + # if we have a Cardano Triplet, but it + # could be slightly off because of + # round-off error + if( + abs(cbrt($a + $b_sqrt_c) + cbrt($a - $b_sqrt_c) - 1) + < + 0.000000001 + ){ + # We have a Cardano Triplet + push(@cardanos, [ $a, $b, $c ]); + + # Break out of all loops if there's a + # count defined and we've hit it + $max = 0 + if($count && (scalar(@cardanos) == $count)); + } + + } + } + } + + return(@cardanos); + +} + + + +################################################################################ +# Compute the cube root of a number +# Takes one argument: +# * The number whose cube root is desired +# Returns: +# * The cube root +################################################################################ +sub cbrt{ + my $x = shift(); + + if($x < 0){ + + # $x is negative; play some sign games + return(-((-$x) ** (1 / 3))); + + } else{ + + # $x is positive; very straightforward + return($x ** (1 / 3)); + + } + +} + + + diff --git a/challenge-148/roger-bell-west/blog.txt b/challenge-148/roger-bell-west/blog.txt new file mode 100644 index 0000000000..654d75d169 --- /dev/null +++ b/challenge-148/roger-bell-west/blog.txt @@ -0,0 +1 @@ +https://blog.firedrake.org/archive/2022/01/The_Weekly_Challenge_148__Eban__Cardano.html diff --git a/challenge-148/steven-wilson/perl/ch-1.pl b/challenge-148/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..28e7f90674 --- /dev/null +++ b/challenge-148/steven-wilson/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +# Week 148 Task 1 +# Eban Numbers +# Write a script to generate all Eban Numbers <= 100. +# An Eban number is a number that has no letter āeā in it +# when the number is spelled in English (American or British). + +use strict; +use warnings; +use feature qw/ say /; +use Lingua::EN::Numbers qw/ num2en /; + +my $max = 100; + +say "Eban Numbers <= $max:"; +for ( 1 .. $max ) { + ( num2en($_) =~ /e/i ) ? next : say $_; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index e21e18c4d3..d0be76504b 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,19 +1,59 @@ { + "chart" : { + "type" : "column" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "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/>" + }, + "xAxis" : { + "type" : "category" + }, "drilldown" : { "series" : [ { - "id" : "E. Choroba", - "name" : "E. Choroba", + "data" : [ + [ + "Blog", + 1 + ] + ], + "id" : "Colin Crain", + "name" : "Colin Crain" + }, + { + "name" : "Dave Jacoby", + "id" : "Dave Jacoby", "data" : [ [ "Perl", 2 + ], + [ + "Blog", + 1 ] ] }, { - "name" : "Flavio Poletti", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" + }, + { "id" : "Flavio Poletti", + "name" : "Flavio Poletti", "data" : [ [ "Perl", @@ -33,6 +73,20 @@ "data" : [ [ "Raku", + 2 + ], + [ + "Blog", + 4 + ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" + }, + { + "data" : [ + [ + "Raku", 1 ] ], @@ -56,6 +110,16 @@ 2 ] ], + "id" : "Matthew Neleigh", + "name" : "Matthew Neleigh" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], "id" : "Niels van Dijke", "name" : "Niels van Dijke" }, @@ -74,16 +138,18 @@ ] }, { + "name" : "Robert DiCicco", + "id" : "Robert DiCicco", "data" : [ [ "Perl", 2 ] - ], - "id" : "Robert DiCicco", - "name" : "Robert DiCicco" + ] }, { + "id" : "Roger Bell_West", + "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -92,10 +158,22 @@ [ "Raku", 2 + ], + [ + "Blog", + 1 ] - ], - "id" : "Roger Bell_West", - "name" : "Roger Bell_West" + ] + }, + { + "name" : "Steven Wilson", + "id" : "Steven Wilson", + "data" : [ + [ + "Perl", + 1 + ] + ] }, { "data" : [ @@ -108,12 +186,12 @@ 2 ] ], - "id" : "Ulrich Rieke", - "name" : "Ulrich Rieke" + "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke" }, { - "id" : "W. Luis Mochan", "name" : "W. Luis Mochan", + "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -126,6 +204,8 @@ ] }, { + "id" : "Walt Mankowski", + "name" : "Walt Mankowski", "data" : [ [ "Perl", @@ -135,59 +215,52 @@ "Blog", 1 ] - ], - "id" : "Walt Mankowski", - "name" : "Walt Mankowski" + ] } ] }, - "title" : { - "text" : "The Weekly Challenge - 148" - }, "plotOptions" : { "series" : { - "borderWidth" : 0, "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } - } - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } }, - "xAxis" : { - "type" : "category" - }, - "subtitle" : { - "text" : "[Champions: 11] Last updated at 2022-01-19 10:22:44 GMT" - }, - "chart" : { - "type" : "column" - }, "legend" : { "enabled" : 0 }, - "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/>" + "subtitle" : { + "text" : "[Champions: 16] Last updated at 2022-01-20 14:16:29 GMT" }, "series" : [ { - "colorByPoint" : 1, "data" : [ { + "name" : "Colin Crain", + "y" : 1, + "drilldown" : "Colin Crain" + }, + { + "y" : 3, + "name" : "Dave Jacoby", + "drilldown" : "Dave Jacoby" + }, + { "drilldown" : "E. Choroba", "name" : "E. Choroba", "y" : 2 }, { - "drilldown" : "Flavio Poletti", "name" : "Flavio Poletti", - "y" : 6 + "y" : 6, + "drilldown" : "Flavio Poletti" + }, + { + "y" : 6, + "name" : "Luca Ferrari", + "drilldown" : "Luca Ferrari" }, { "y" : 1, @@ -195,33 +268,43 @@ "drilldown" : "Mark Anderson" }, { - "y" : 2, "drilldown" : "Marton Polgar", + "y" : 2, "name" : "Marton Polgar" }, { + "drilldown" : "Matthew Neleigh", + "name" : "Matthew Neleigh", + "y" : 2 + }, + { "drilldown" : "Niels van Dijke", "name" : "Niels van Dijke", "y" : 2 }, { - "y" : 3, "drilldown" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "y" : 3 }, { "y" : 2, - "drilldown" : "Robert DiCicco", - "name" : "Robert DiCicco" + "name" : "Robert DiCicco", + "drilldown" : "Robert DiCicco" }, { - "y" : 4, - "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West" + "y" : 5, + "name" : "Roger Bell_West", + "drilldown" : "Roger Bell_West" + }, + { + "y" : 1, + "name" : "Steven Wilson", + "drilldown" : "Steven Wilson" }, { - "name" : "Ulrich Rieke", "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke", "y" : 3 }, { @@ -230,12 +313,16 @@ "y" : 3 }, { - "y" : 3, "drilldown" : "Walt Mankowski", - "name" : "Walt Mankowski" + "name" : "Walt Mankowski", + "y" : 3 } ], + "colorByPoint" : 1, "name" : "The Weekly Challenge - 148" } - ] + ], + "title" : { + "text" : "The Weekly Challenge - 148" + } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 81f1a842c9..10ad9c9e2f 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,63 +1,63 @@ { - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2021]" - }, - "yAxis" : { - "min" : 0, - "title" : { - "text" : null - } - }, "xAxis" : { - "type" : "category", "labels" : { "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" } - } + }, + "type" : "category" }, - "subtitle" : { - "text" : "Last updated at 2022-01-19 10:22:44 GMT" + "yAxis" : { + "title" : { + "text" : null + }, + "min" : 0 + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" }, "chart" : { "type" : "column" }, - "legend" : { - "enabled" : "false" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2021]" }, "series" : [ { - "name" : "Contributions", "dataLabels" : { "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" }, - "format" : "{point.y:.0f}", - "y" : 10, - "enabled" : "true", "rotation" : -90, + "enabled" : "true", + "color" : "#FFFFFF", "align" : "right", - "color" : "#FFFFFF" + "y" : 10, + "format" : "{point.y:.0f}" }, + "name" : "Contributions", "data" : [ [ "Blog", - 2199 + 2206 ], [ "Perl", - 7124 + 7129 ], [ "Raku", - 4288 + 4290 ] ] } - ] + ], + "legend" : { + "enabled" : "false" + }, + "subtitle" : { + "text" : "Last updated at 2022-01-20 14:16:29 GMT" + } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index e38e24cf0e..8f439be8b9 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -4,786 +4,19 @@ "headerFormat" : "<span style=\"font-size:11px\"></span>", "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" }, - "series" : [ - { - "data" : [ - { - "y" : 161, - "name" : "#001", - "drilldown" : "001" - }, - { - "name" : "#002", - "drilldown" : "002", - "y" : 125 - }, - { - "y" : 83, - "name" : "#003", - "drilldown" : "003" - }, - { - "y" : 99, - "drilldown" : "004", - "name" : "#004" - }, - { - "y" : 78, - "drilldown" : "005", - "name" : "#005" - }, - { - "y" : 58, - "drilldown" : "006", - "name" : "#006" - }, - { - "y" : 64, - "name" : "#007", - "drilldown" : "007" - }, - { - "drilldown" : "008", - "name" : "#008", - "y" : 78 - }, - { - "y" : 76, - "name" : "#009", - "drilldown" : "009" - }, - { - "drilldown" : "010", - "name" : "#010", - "y" : 65 - }, - { - "name" : "#011", - "drilldown" : "011", - "y" : 85 - }, - { - "drilldown" : "012", - "name" : "#012", - "y" : 89 - }, - { - "y" : 85, - "name" : "#013", - "drilldown" : "013" - }, - { - "y" : 101, - "drilldown" : "014", - "name" : "#014" - }, - { - "y" : 99, - "name" : "#015", - "drilldown" : "015" - }, - { - "y" : 71, - "drilldown" : "016", - "name" : "#016" - }, - { - "y" : 84, - "name" : "#017", - "drilldown" : "017" - }, - { - "y" : 81, - "name" : "#018", - "drilldown" : "018" - }, - { - "y" : 103, - "name" : "#019", - "drilldown" : "019" - }, - { - "y" : 101, - |
