diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-11-09 14:19:57 +0000 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-11-09 14:19:57 +0000 |
| commit | ef2fd26d0c6fedafdff60cd1b13ae70fc0f79568 (patch) | |
| tree | 20c133871f080f2809a23917ddb47cd43e8fa470 | |
| parent | fdfcad5c82799400ebe0272359935103c313c1d5 (diff) | |
| download | perlweeklychallenge-club-ef2fd26d0c6fedafdff60cd1b13ae70fc0f79568.tar.gz perlweeklychallenge-club-ef2fd26d0c6fedafdff60cd1b13ae70fc0f79568.tar.bz2 perlweeklychallenge-club-ef2fd26d0c6fedafdff60cd1b13ae70fc0f79568.zip | |
- Added solutions by Peter Meszaros.
- Added solutions by Arne Sommer.
- Added solutions by Luca Ferrari.
- Added solutions by W. Luis Mochan.
- Added solutions by Simon Green.
- Added solutions by Jaldhar H. Vyas.
- Added solutions by Roger Bell_West.
25 files changed, 288 insertions, 79 deletions
diff --git a/challenge-346/ulrich-rieke/perl/ch-2.pl b/challenge-346/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..adc0eac328 --- /dev/null +++ b/challenge-346/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,109 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use Algorithm::Combinatorics qw ( variations_with_repetition ) ;
+use List::Util qw ( sum ) ;
+use Data::Dumper ;
+
+sub parseTerm {
+ my $term = shift ;
+ while ( $term =~ s/(\d+)\*(\d+)/$1 * $2/ge ) {
+ }
+ while ( $term =~ /^(\-?\d+)([+-])(\d+)/ ) {
+ my ($a , $op , $b ) = ($1 , $2 , $3) ;
+ my $result = eval "$a$op$b" ;
+ $term =~ s/^(\-?\d+)([+-])(\d+)/$result/ ;
+ }
+ return $term ;
+}
+
+sub findAllLengthCombinations {
+ my $wordlength = shift ;
+ my @allCombis ;
+ my @numbers = (1..$wordlength - 1) ;
+ for my $num( 2..$wordlength ) {
+ my $iter = variations_with_repetition( \@numbers , $num ) ;
+ while ( my $c = $iter->next ) {
+ if ( sum( @$c ) == $wordlength ) {
+ push( @allCombis , $c ) ;
+ }
+ }
+ }
+ return @allCombis ;
+}
+
+sub findOperatorCombinations {
+ my $divisions = shift ;
+ my @combinators = ('+' , '-' , '*') ;
+ my @opCombis ;
+ my $iter = variations_with_repetition( \@combinators , $divisions ) ;
+ while ( my $c = $iter->next ) {
+ push( @opCombis , $c ) ;
+ }
+ return @opCombis ;
+}
+
+sub splitTermAtPositions {
+ my $term = shift ;
+ my $positions = shift ;
+ my $pos = 0 ;
+ my @splitTerms ;
+ while ( @$positions ) {
+ my $len = shift( @$positions ) ;
+ my $part = substr( $term , $pos , $len ) ;
+ push( @splitTerms , $part ) ;
+ $pos += $len ;
+ }
+ return @splitTerms ;
+}
+
+sub combineWithOperators {
+ my $splitterms = shift ;
+ my $len = scalar( @$splitterms ) ;
+ my @opCombinations = findOperatorCombinations($len - 1 ) ;
+ my @combis ;
+ if ( $len == 2 ) {
+ my $total ;
+ for my $op ( @opCombinations ) {
+ $total .= $splitterms->[0] . $op->[0] . $splitterms->[1] ;
+ push( @combis , $total ) ;
+ $total = "" ;
+ }
+ }
+ else {
+ my $total ;
+ for my $combi ( @opCombinations ) {
+ my $pos = 0 ;
+ while ( $pos < $len ) {
+ $total .= $splitterms->[$pos] ;
+ if ( $pos < $len - 1 ) {
+ $total .= $combi->[$pos] ;
+ }
+ $pos++ ;
+ }
+ push( @combis , $total ) ;
+ $total = "" ;
+ }
+ }
+ return @combis ;
+}
+say "Enter a term consisting of digits only!" ;
+my $term = <STDIN> ;
+chomp $term ;
+say "Enter a number!" ;
+my $target = <STDIN> ;
+chomp $target ;
+if ( $term eq $target ) {
+ say '(' . join(',' , ("$term+0" , "$term-0")) . ')' ;
+}
+else {
+ my @allCombis ;
+ my @allLengths = findAllLengthCombinations( length( $term ) ) ;
+ for my $combi( @allLengths ) {
+ my @splitTerm = splitTermAtPositions( $term , $combi ) ;
+ my @combisForLength = combineWithOperators( \@splitTerm ) ;
+ map { push( @allCombis , $_ ) } @combisForLength ;
+ }
+ say '(' . join( ',' , grep { parseTerm($_) == $target } @allCombis ) . ')' ;
+}
diff --git a/guests.json b/guests.json index eb66fce262..baae99055d 100644 --- a/guests.json +++ b/guests.json @@ -5,6 +5,7 @@ "ashwin-shenoy" : "Ashwin Shenoy", "aviral-goel" : "Aviral Goel", "benjamin-andre" : "Benjamin Andre", + "beespider" : "beespider", "chazzka" : "Chazzka", "conor-hoekstra" : "Conor Hoekstra", "daniel-aberger" : "Daniel Aberger", diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 1aafbb1776..42f412eecb 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -41,6 +41,20 @@ { "data" : [ [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Arne Sommer", + "name" : "Arne Sommer" + }, + { + "data" : [ + [ "Perl", 2 ] @@ -65,6 +79,24 @@ 2 ], [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ "Blog", 1 ] @@ -96,6 +128,20 @@ "data" : [ [ "Raku", + 1 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" + }, + { + "data" : [ + [ + "Raku", 2 ] ], @@ -147,6 +193,20 @@ 2 ] ], + "id" : "Peter Meszaros", + "name" : "Peter Meszaros" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], "id" : "Roger Bell_West", "name" : "Roger Bell_West" }, @@ -158,6 +218,20 @@ ], [ "Blog", + 1 + ] + ], + "id" : "Simon Green", + "name" : "Simon Green" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", 2 ] ], @@ -168,7 +242,7 @@ "data" : [ [ "Perl", - 1 + 2 ], [ "Raku", @@ -236,6 +310,11 @@ "y" : 1 }, { + "drilldown" : "Arne Sommer", + "name" : "Arne Sommer", + "y" : 3 + }, + { "drilldown" : "David Ferrone", "name" : "David Ferrone", "y" : 2 @@ -246,6 +325,11 @@ "y" : 2 }, { + "drilldown" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas", + "y" : 5 + }, + { "drilldown" : "Jorg Sommrey", "name" : "Jorg Sommrey", "y" : 3 @@ -261,6 +345,11 @@ "y" : 2 }, { + "drilldown" : "Luca Ferrari", + "name" : "Luca Ferrari", + "y" : 2 + }, + { "drilldown" : "Mark Anderson", "name" : "Mark Anderson", "y" : 2 @@ -281,9 +370,19 @@ "y" : 3 }, { + "drilldown" : "Peter Meszaros", + "name" : "Peter Meszaros", + "y" : 2 + }, + { "drilldown" : "Roger Bell_West", "name" : "Roger Bell_West", - "y" : 2 + "y" : 3 + }, + { + "drilldown" : "Simon Green", + "name" : "Simon Green", + "y" : 3 }, { "drilldown" : "Thomas Kohler", @@ -293,7 +392,7 @@ { "drilldown" : "Ulrich Rieke", "name" : "Ulrich Rieke", - "y" : 2 + "y" : 3 }, { "drilldown" : "Vinod Kumar K", @@ -310,7 +409,7 @@ } ], "subtitle" : { - "text" : "[Champions: 17] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 22] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge - 346" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index cc31fb5709..4a903eea39 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -970,7 +970,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index 7cc5a65e01..0cb41e04ba 100644 --- a/stats/pwc-language-breakdown-2020.json +++ b/stats/pwc-language-breakdown-2020.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index a4e46f47a0..43d80d5a3f 100644 --- a/stats/pwc-language-breakdown-2021.json +++ b/stats/pwc-language-breakdown-2021.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 30ba6c8494..e7db50e783 100644 --- a/stats/pwc-language-breakdown-2022.json +++ b/stats/pwc-language-breakdown-2022.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index a9e312391e..89e99f9e33 100644 --- a/stats/pwc-language-breakdown-2023.json +++ b/stats/pwc-language-breakdown-2023.json @@ -1200,7 +1200,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index 58e0c0b6df..5eabe3564f 100644 --- a/stats/pwc-language-breakdown-2024.json +++ b/stats/pwc-language-breakdown-2024.json @@ -1246,7 +1246,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index ad17c72154..088f4b1bf3 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,15 +8,15 @@ "data" : [ [ "Perl", - 28 + 35 ], [ "Raku", - 5 + 10 ], [ "Blog", - 6 + 11 ] ], "id" : "346", @@ -817,7 +817,7 @@ { "drilldown" : "346", "name" : "346", - "y" : 39 + "y" : 56 }, { "drilldown" : "345", @@ -1039,7 +1039,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index eb2396354d..88b3c70120 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,15 +10,15 @@ "data" : [ [ "Perl", - 17825 + 17832 ], [ "Raku", - 9871 + 9876 ], [ "Blog", - 6382 + 6387 ] ], "dataLabels" : { @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index 03d2b14e79..58ab17fd87 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -8,11 +8,11 @@ "data" : [ [ "Raku", - 472 + 473 ], [ "Blog", - 1219 + 1220 ] ], "id" : "Luca Ferrari", @@ -22,15 +22,15 @@ "data" : [ [ "Perl", - 640 + 642 ], [ "Raku", - 640 + 642 ], [ "Blog", - 320 + 321 ] ], "id" : "Jaldhar H. Vyas", @@ -48,7 +48,7 @@ ], [ "Blog", - 324 + 325 ] ], "id" : "Roger Bell_West", @@ -80,11 +80,11 @@ ], [ "Raku", - 687 + 689 ], [ "Blog", - 344 + 345 ] ], "id" : "Arne Sommer", @@ -112,7 +112,7 @@ "data" : [ [ "Perl", - 529 + 530 ], [ "Raku", @@ -262,11 +262,11 @@ "data" : [ [ "Perl", - 439 + 441 ], [ "Blog", - 217 + 218 ] ], "id" : "Simon Green", @@ -618,7 +618,7 @@ "data" : [ [ "Perl", - 292 + 294 ] ], "id" : "Peter Meszaros", @@ -797,17 +797,17 @@ { "drilldown" : "Luca Ferrari", "name" : "1: Luca Ferrari", - "y" : 3382 + "y" : 3386 }, { "drilldown" : "Jaldhar H. Vyas", "name" : "2: Jaldhar H. Vyas", - "y" : 3200 + "y" : 3210 }, { "drilldown" : "Roger Bell_West", "name" : "3: Roger Bell_West", - "y" : 3152 + "y" : 3154 }, { "drilldown" : "Laurent Rosenfeld", @@ -817,7 +817,7 @@ { "drilldown" : "Arne Sommer", "name" : "5: Arne Sommer", - "y" : 2368 + "y" : 2374 }, { "drilldown" : "Athanasius", @@ -827,7 +827,7 @@ { "drilldown" : "Ulrich Rieke", "name" : "7: Ulrich Rieke", - "y" : 2132 + "y" : 2134 }, { "drilldown" : "Flavio Poletti", @@ -872,7 +872,7 @@ { "drilldown" : "Simon Green", "name" : "16: Simon Green", - "y" : 1312 + "y" : 1318 }, { "drilldown" : "Peter Campbell Smith", @@ -992,7 +992,7 @@ { "drilldown" : "Peter Meszaros", "name" : "40: Peter Meszaros", - "y" : 584 + "y" : 588 }, { "drilldown" : "Abigail", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-11-07 23:57:46 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index b27f37be00..7811af64ff 100644 --- a/stats/pwc-summary-1-30.json +++ b/stats/pwc-summary-1-30.json @@ -72,7 +72,7 @@ 0, 0, 2, - 687, + 689, 0, 23 ], @@ -107,7 +107,7 @@ 0, 0, 0, - 344, + 345, 0, 0 ], @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-121-150.json b/stats/pwc-summary-121-150.json index 03480477a2..4a7e536893 100644 --- a/stats/pwc-summary-121-150.json +++ b/stats/pwc-summary-121-150.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-151-180.json b/stats/pwc-summary-151-180.json index c4fd61a302..a3065a2966 100644 --- a/stats/pwc-summary-151-180.json +++ b/stats/pwc-summary-151-180.json @@ -63,7 +63,7 @@ 0, 10, 55, - 472, + 473, 14, 4, 0, @@ -98,7 +98,7 @@ 0, 0, 30, - 1219, + 1220, 0, 0, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-181-210.json b/stats/pwc-summary-181-210.json index 2caff3818b..b66fa5cd3b 100644 --- a/stats/pwc-summary-181-210.json +++ b/stats/pwc-summary-181-210.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-211-240.json b/stats/pwc-summary-211-240.json index a7885afa79..82903905de 100644 --- a/stats/pwc-summary-211-240.json +++ b/stats/pwc-summary-211-240.json @@ -28,7 +28,7 @@ 0, 418, 1, - 292, + 294, 10, 11, 7, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-241-270.json b/stats/pwc-summary-241-270.json index da8d28ae9c..d3a4304f3c 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -104,7 +104,7 @@ 7, 2, 0, - 324, + 325, 0, 62, 1, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-271-300.json b/stats/pwc-summary-271-300.json index 520b2f71a6..6501d8f6d2 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -19,7 +19,7 @@ 0, 22, 0, - 439, + 441, 7, 5, 4, @@ -89,7 +89,7 @@ 0, 0, 3, - 217, + 218, 0, 17, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-301-330.json b/stats/pwc-summary-301-330.json index 17d3440769..bc92af7d38 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -21,7 +21,7 @@ 0, 2, 4, - 529, + 530, 24, 18, 16, @@ -109,7 +109,7 @@ } ], "subtitle" : { - "text" : "[Champions: 28] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 28] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-31-60.json b/stats/pwc-summary-31-60.json index eb953db5f6..6d28d96a35 100644 --- a/stats/pwc-summary-31-60.json +++ b/stats/pwc-summary-31-60.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-61-90.json b/stats/pwc-summary-61-90.json index 7ebf5b58e4..4743079297 100644 --- a/stats/pwc-summary-61-90.json +++ b/stats/pwc-summary-61-90.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-11-07 23:57:46 GMT" + "text" : "[Champions: 30] Last updated at 2025-11-09 14:19:34 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-91-120.json b/stats/pwc-summary-91-120.json index 4811bf6dcd..c066a172ff 100644 --- a/stats/pwc-summary-91-120.json +++ b/stats/pwc-summary-91-120.json @@ -34,7 + |
