From 682d4c758b46d1c5a1e27754a3beb4ea784cb770 Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Mon, 13 Oct 2025 09:23:29 -0500 Subject: Week 343 solutions --- challenge-343/bob-lied/README.md | 6 +- challenge-343/bob-lied/perl/ch-1.pl | 73 ++++++++++++++++ challenge-343/bob-lied/perl/ch-2.pl | 162 ++++++++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+), 3 deletions(-) create mode 100644 challenge-343/bob-lied/perl/ch-1.pl create mode 100644 challenge-343/bob-lied/perl/ch-2.pl diff --git a/challenge-343/bob-lied/README.md b/challenge-343/bob-lied/README.md index 98b149c185..9ef043028b 100644 --- a/challenge-343/bob-lied/README.md +++ b/challenge-343/bob-lied/README.md @@ -1,5 +1,5 @@ -# Solutions to weekly challenge 342 by Bob Lied +# Solutions to weekly challenge 343 by Bob Lied -## [PWC](https://perlweeklychallenge.org/blog/perl-weekly-challenge-342/) -## [GitHub](https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-342/bob-lied) +## [PWC](https://perlweeklychallenge.org/blog/perl-weekly-challenge-343/) +## [GitHub](https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-343/bob-lied) [Blog](https://dev.to/boblied/pwc-342-balance-4eh4) diff --git a/challenge-343/bob-lied/perl/ch-1.pl b/challenge-343/bob-lied/perl/ch-1.pl new file mode 100644 index 0000000000..8bfdbe2e76 --- /dev/null +++ b/challenge-343/bob-lied/perl/ch-1.pl @@ -0,0 +1,73 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# Copyright (c) 2025, Bob Lied +#============================================================================= +# ch-1.pl Perl Weekly Challenge 343 Task 1 Zero Friend +#============================================================================= +# You are given a list of numbers. +# Find the number that is closest to zero and return its distance to zero. +# Example 1 Input: @nums = (4, 2, -1, 3, -2) +# Output: 1 +# Example 2 Input: @nums = (-5, 5, -3, 3, -1, 1) +# Output: 1 +# Example 3 Input: @ums = (7, -3, 0, 2, -8) +# Output: 0 +# Example 4 Input: @nums = (-2, -5, -1, -8) +# Output: 1 +# Example 5 Input: @nums = (-2, 2, -4, 4, -1, 1) +# Output: 1 +#============================================================================= + +use v5.42; + + +use Getopt::Long; +my $Verbose = false; +my $DoTest = false; +my $Benchmark = 0; + +GetOptions("test" => \$DoTest, "verbose" => \$Verbose, "benchmark:i" => \$Benchmark); +my $logger; +{ + use Log::Log4perl qw(:easy); + Log::Log4perl->easy_init({ level => ($Verbose ? $DEBUG : $INFO ), + layout => "%d{HH:mm:ss.SSS} %p{1} %m%n" }); + $logger = Log::Log4perl->get_logger(); +} +#============================================================================= + +exit(!runTest()) if $DoTest; +exit( runBenchmark($Benchmark) ) if $Benchmark; + +say zeroFriend(@ARGV); + +#============================================================================= +sub zeroFriend(@num) +{ + use List::Util qw/min/; + return min map { abs($_) } @num; +} + +sub runTest +{ + use Test2::V0; + + is( zeroFriend( 4, 2, -1, 3, -2 ) , 1, "Example 1"); + is( zeroFriend( -5, 5, -3, 3, -1, 1) , 1, "Example 2"); + is( zeroFriend( 7, -3, 0, 2, -8 ) , 0, "Example 3"); + is( zeroFriend( -2, -5, -1, -8 ) , 1, "Example 4"); + is( zeroFriend( -2, 2, -4, 4, -1, 1) , 1, "Example 5"); + is( zeroFriend( -3, -7, 100, 1.5 ) , 1.5, "Something other than 1 or 0"); + + done_testing; +} + +sub runBenchmark($repeat) +{ + use Benchmark qw/cmpthese/; + + cmpthese($repeat, { + label => sub { }, + }); +} diff --git a/challenge-343/bob-lied/perl/ch-2.pl b/challenge-343/bob-lied/perl/ch-2.pl new file mode 100644 index 0000000000..fc413251b4 --- /dev/null +++ b/challenge-343/bob-lied/perl/ch-2.pl @@ -0,0 +1,162 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# Copyright (c) 2025, Bob Lied +#============================================================================= +# ch-2.pl Perl Weekly Challenge 343 Task 2 Champion Team +#============================================================================= +# You have n teams in a tournament. A matrix grid tells you which team is +# stronger between any two teams: +# If grid[i][j] == 1, then team i is stronger than team j +# If grid[i][j] == 0, then team j is stronger than team i +# Find the champion team - the one with most wins, or if there is no single +# such team, the strongest of the teams with most wins. (You may assume +# that there is a definite answer.) +# +# Example 1 Input: @grid = ( [0, 1, 1], +# [0, 0, 1], +# [0, 0, 0],) +# Output: Team 0 +# [0, 1, 1] => Team 0 beats Team 1 and Team 2 +# [0, 0, 1] => Team 1 beats Team 2 +# [0, 0, 0] => Team 2 loses to all +# +# Example 2 Input: @grid = ( [0, 1, 0, 0], +# [0, 0, 0, 0], +# [1, 1, 0, 0], +# [1, 1, 1, 0],) +# Output: Team 3 +# [0, 1, 0, 0] => Team 0 beats only Team 1 +# [0, 0, 0, 0] => Team 1 loses to all +# [1, 1, 0, 0] => Team 2 beats Team 0 and Team 1 +# [1, 1, 1, 0] => Team 3 beats everyone +# +# Example 3 Input: @grid = ( [0, 1, 0, 1], +# [0, 0, 1, 1], +# [1, 0, 0, 0], +# [0, 0, 1, 0],) +# Output: Team 0 +# [0, 1, 0, 1] => Team 0 beats teams 1 and 3 +# [0, 0, 1, 1] => Team 1 beats teams 2 and 3 +# [1, 0, 0, 0] => Team 2 beats team 0 +# [0, 0, 1, 0] => Team 3 beats team 2 +# Of the teams with 2 wins, Team 0 beats team 1. +# +# Example 4 Input: @grid = ( [0, 1, 1], +# [0, 0, 0], +# [0, 1, 0],) +# Output: Team 0 +# [0, 1, 1] => Team 0 beats Team 1 and Team 2 +# [0, 0, 0] => Team 1 loses to Team 2 +# [0, 1, 0] => Team 2 beats Team 1 but loses to Team 0 +# +# Example 5 Input: @grid = ( [0, 0, 0, 0, 0], +# [1, 0, 0, 0, 0], +# [1, 1, 0, 1, 1], +# [1, 1, 0, 0, 0], +# [1, 1, 0, 1, 0],) +# Output: Team 2 +# [0, 0, 0, 0, 0] => Team 0 loses to all +# [1, 0, 0, 0, 0] => Team 1 beats only Team 0 +# [1, 1, 0, 1, 1] => Team 2 beats everyone except self +# [1, 1, 0, 0, 0] => Team 3 loses to Team 2 +# [1, 1, 0, 1, 0] => Team 4 loses to Team 2 +#============================================================================= + +use v5.42; + + +use Getopt::Long; +my $Verbose = false; +my $DoTest = false; +my $Benchmark = 0; + +GetOptions("test" => \$DoTest, "verbose" => \$Verbose, "benchmark:i" => \$Benchmark); +my $logger; +{ + use Log::Log4perl qw(:easy); + Log::Log4perl->easy_init({ level => ($Verbose ? $DEBUG : $INFO ), + layout => "%d{HH:mm:ss.SSS} %p{1} %m%n" }); + $logger = Log::Log4perl->get_logger(); +} +#============================================================================= + +exit(!runTest()) if $DoTest; +exit( runBenchmark($Benchmark) ) if $Benchmark; + +# Supply rows as comma lists, example: +# perl ch-1.pl 0,1,1 0,0,1 0,0,0 +my @GRID = map { [ split(',', $_) ] } @ARGV; +say join " ", map { !defined($_) ? "NONE" : $_ } champion(@GRID); + +#============================================================================= +sub champion(@grid) +{ + use List::Util qw/max sum any/; + use List::MoreUtils qw/indexes/; + + my @strength = map { sum($_->@*) } @grid; + my $maxStrength = max @strength; + my @strongest = indexes { $_ == $maxStrength } @strength; + + # Eliminate losers + # + #my @champ; + #for my $team1 ( @strongest ) + #{ + # next if any { $grid[$_][$team1] } @strongest ; + # push @champ, $team1; + #} + # + + # For a possible tie, choose the smallest + #my @champ = grep { my $t = $_; ! any { $grid[$_][$t]} @strongest } @strongest; + #return $champ[0]; + + return (grep { my $t = $_; ! any { $grid[$_][$t]} @strongest } @strongest)[0]; +} + +sub runTest +{ + use Test2::V0; + + my @case = ( + { case => "Example 1", expect => 0, + input => [ [0,1,1], [0,0,1], [0,0,0] ] + } , + { case => "Example 2", expect => 3, + input => [ [0,1,0,0], [0,0,0,0], [1,1,0,0], [1,1,1,0] ], + } , + { case => "Example 3", expect => 0, + input => [ [0,1,0,1], [0,0,1,1], [1,0,0,0], [0,0,1,0] ] + } , + { case => "Example 4", expect => 0, + input => [ [0,1,1], [0,0,0], [0,1,0] ] + } , + { case => "Example 5", expect => 2, + input => [ [0,0,0,0,0], [1,0,0,0,0], [1,1,0,1,1], [1,1,0,0,0], [1,1,0,1,0] ] + } , + { case => "Rock paper scissors", expect => undef, + input => [ [0,0,1], [1,0,0], [0,1,0] ] + } , + { case => "Tied ", expect => 1, + input => [ [0,0,0,0,0,0], [0,0,0,0,1,1], [0,0,0,0,0,0], [0,0,1,1,0,0], [0,0,0,0,0], [0,0,0,0,0,0] ] + } , + ); + + for ( @case ) + { + is( champion( $_->{input}->@* ), $_->{expect}, $_->{case}); + } + + done_testing; +} + +sub runBenchmark($repeat) +{ + use Benchmark qw/cmpthese/; + + cmpthese($repeat, { + label => sub { }, + }); +} -- cgit From 07a79819423e01b25d3c2e8e2912a686268d6ed5 Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Mon, 13 Oct 2025 17:51:11 -0500 Subject: Task 2 handle ties better --- challenge-343/bob-lied/perl/ch-2.pl | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/challenge-343/bob-lied/perl/ch-2.pl b/challenge-343/bob-lied/perl/ch-2.pl index fc413251b4..bcc09fd298 100644 --- a/challenge-343/bob-lied/perl/ch-2.pl +++ b/challenge-343/bob-lied/perl/ch-2.pl @@ -100,20 +100,10 @@ sub champion(@grid) my @strongest = indexes { $_ == $maxStrength } @strength; # Eliminate losers - # - #my @champ; - #for my $team1 ( @strongest ) - #{ - # next if any { $grid[$_][$team1] } @strongest ; - # push @champ, $team1; - #} - # - - # For a possible tie, choose the smallest - #my @champ = grep { my $t = $_; ! any { $grid[$_][$t]} @strongest } @strongest; - #return $champ[0]; - - return (grep { my $t = $_; ! any { $grid[$_][$t]} @strongest } @strongest)[0]; + my @champ = grep { my $t = $_; ! any { $grid[$_][$t]} @strongest } @strongest; + + # For a possible tie, return a list. If no champions, it's an N-way tie. + return ( @champ > 0 ? "@champ" : "@strongest" ); } sub runTest @@ -136,11 +126,11 @@ sub runTest { case => "Example 5", expect => 2, input => [ [0,0,0,0,0], [1,0,0,0,0], [1,1,0,1,1], [1,1,0,0,0], [1,1,0,1,0] ] } , - { case => "Rock paper scissors", expect => undef, + { case => "Rock paper scissors", expect => "0 1 2", input => [ [0,0,1], [1,0,0], [0,1,0] ] } , - { case => "Tied ", expect => 1, - input => [ [0,0,0,0,0,0], [0,0,0,0,1,1], [0,0,0,0,0,0], [0,0,1,1,0,0], [0,0,0,0,0], [0,0,0,0,0,0] ] + { case => "Tied ", expect => "1 3", + input => [ [0,0,0,0,0,0], [0,0,0,0,1,1], [0,0,0,0,0,0], [1,0,1,0,0,0], [0,0,0,0,0], [0,0,0,0,0,0] ] } , ); -- cgit From 56243d57fe88c2800c6ca9e67ca7de291b719c32 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 14 Oct 2025 09:39:42 +0100 Subject: - Added blog post by Bob Lied. --- challenge-342/bob-lied/blog.txt | 1 - challenge-342/bob-lied/blog1.txt | 1 + stats/pwc-challenge-342.json | 6 +++--- stats/pwc-current.json | 2 +- stats/pwc-language-breakdown-2019.json | 2 +- stats/pwc-language-breakdown-2020.json | 2 +- stats/pwc-language-breakdown-2021.json | 2 +- stats/pwc-language-breakdown-2022.json | 2 +- stats/pwc-language-breakdown-2023.json | 2 +- stats/pwc-language-breakdown-2024.json | 2 +- stats/pwc-language-breakdown-2025.json | 6 +++--- stats/pwc-language-breakdown-summary.json | 4 ++-- stats/pwc-leaders.json | 6 +++--- stats/pwc-summary-1-30.json | 2 +- stats/pwc-summary-121-150.json | 2 +- stats/pwc-summary-151-180.json | 2 +- stats/pwc-summary-181-210.json | 2 +- stats/pwc-summary-211-240.json | 2 +- stats/pwc-summary-241-270.json | 2 +- stats/pwc-summary-271-300.json | 2 +- stats/pwc-summary-301-330.json | 2 +- stats/pwc-summary-31-60.json | 6 +++--- stats/pwc-summary-61-90.json | 2 +- stats/pwc-summary-91-120.json | 2 +- stats/pwc-summary.json | 4 ++-- stats/pwc-yearly-language-summary.json | 6 +++--- 26 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 challenge-342/bob-lied/blog1.txt diff --git a/challenge-342/bob-lied/blog.txt b/challenge-342/bob-lied/blog.txt index 84cd2f56ae..1d7ff08464 100644 --- a/challenge-342/bob-lied/blog.txt +++ b/challenge-342/bob-lied/blog.txt @@ -1,2 +1 @@ https://dev.to/boblied/pwc-342-balance-4eh4 -https://dev.to/boblied/pwc-342-max-score-all-your-0s-and-1s-are-belong-to-us-4bns diff --git a/challenge-342/bob-lied/blog1.txt b/challenge-342/bob-lied/blog1.txt new file mode 100644 index 0000000000..94be66fc1d --- /dev/null +++ b/challenge-342/bob-lied/blog1.txt @@ -0,0 +1 @@ +https://dev.to/boblied/pwc-342-max-score-all-your-0s-and-1s-are-belong-to-us-4bns diff --git a/stats/pwc-challenge-342.json b/stats/pwc-challenge-342.json index 543f8fa55c..6e63703481 100644 --- a/stats/pwc-challenge-342.json +++ b/stats/pwc-challenge-342.json @@ -84,7 +84,7 @@ ], [ "Blog", - 1 + 2 ] ], "id" : "Bob Lied", @@ -433,7 +433,7 @@ { "drilldown" : "Bob Lied", "name" : "Bob Lied", - "y" : 3 + "y" : 4 }, { "drilldown" : "David Ferrone", @@ -560,7 +560,7 @@ } ], "subtitle" : { - "text" : "[Champions: 31] Last updated at 2025-10-14 08:35:55 GMT" + "text" : "[Champions: 31] Last updated at 2025-10-14 08:39:26 GMT" }, "title" : { "text" : "The Weekly Challenge - 342" diff --git a/stats/pwc-current.json b/stats/pwc-current.json index a2df5ad737..ac6a443ce2 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -201,7 +201,7 @@ } ], "subtitle" : { - "text" : "[Champions: 10] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 10] Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge - 343" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 6d93854b95..409b44eb7d 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-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index c444434e6f..14f50b04f2 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-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index ebee8adb20..2d2931b807 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-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index b21de4de8f..115b592487 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-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index 20f8210725..c0b70cbfbc 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-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index ebb34c1cab..aa12d6e20a 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-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index 2c77d8c64a..aae1ab37aa 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -34,7 +34,7 @@ ], [ "Blog", - 13 + 14 ] ], "id" : "342", @@ -768,7 +768,7 @@ { "drilldown" : "342", "name" : "342", - "y" : 82 + "y" : 83 }, { "drilldown" : "341", @@ -970,7 +970,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index e0afe8555d..851f463fd5 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -18,7 +18,7 @@ ], [ "Blog", - 6331 + 6332 ] ], "dataLabels" : { @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-10-14 08:36:01 GMT" + "text" : "Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index 7d5669156b..018c9d82c7 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -432,7 +432,7 @@ ], [ "Blog", - 49 + 50 ] ], "id" : "Bob Lied", @@ -927,7 +927,7 @@ { "drilldown" : "Bob Lied", "name" : "27: Bob Lied", - "y" : 874 + "y" : 876 }, { "drilldown" : "Robbie Hatley", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index 4166d0fc54..67ec96fdae 100644 --- a/stats/pwc-summary-1-30.json +++ b/stats/pwc-summary-1-30.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 e35cde0d2a..0f41b0d44c 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-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 541f137a8b..254cacf23d 100644 --- a/stats/pwc-summary-151-180.json +++ b/stats/pwc-summary-151-180.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 2955d7ba27..c8be90274b 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-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 f6b074e468..d732ec7a58 100644 --- a/stats/pwc-summary-211-240.json +++ b/stats/pwc-summary-211-240.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 edbfc97945..8fa57e4e58 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 46e9b60194..9b7aef0796 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 084879e24e..f0bfae0b53 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -109,7 +109,7 @@ } ], "subtitle" : { - "text" : "[Champions: 28] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 28] Last updated at 2025-10-14 08:39:32 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 41d277a2a5..9f28522df4 100644 --- a/stats/pwc-summary-31-60.json +++ b/stats/pwc-summary-31-60.json @@ -69,8 +69,8 @@ 9, 0, 0, - 2, 17, + 2, 0, 194, 0, @@ -93,7 +93,7 @@ 0, 0, 0, - 49, + 50, 0, 19, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 4476d9e077..12bb7e5467 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-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 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 faedea48ec..1cd2223be9 100644 --- a/stats/pwc-summary-91-120.json +++ b/stats/pwc-summary-91-120.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index f43ede462d..1943b1ebb5 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -397,8 +397,8 @@ 6, 0, 0, - 1, 9, + 1, 0, 104, 0, @@ -1009,7 +1009,7 @@ } ], "subtitle" : { - "text" : "[Champions: 328] Last updated at 2025-10-14 08:36:01 GMT" + "text" : "[Champions: 328] Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-yearly-language-summary.json b/stats/pwc-yearly-language-summary.json index bf43a4924e..71d4228ab4 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -16,7 +16,7 @@ ], [ "Blog", - 741 + 742 ] ], "id" : "2025", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 3551 + "y" : 3552 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:36:01 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" }, "title" : { "text" : "The Weekly Challenge Language" -- cgit From aaf8161ab1a7c4071374e27c9001c3bef0f0d6be Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 14 Oct 2025 10:01:50 +0100 Subject: - Added solutions in Perl, Raku and Python. --- challenge-343/mohammad-anwar/perl/ch-1.pl | 22 ++++++++++++++++++++++ challenge-343/mohammad-anwar/python/ch-1.py | 23 +++++++++++++++++++++++ challenge-343/mohammad-anwar/raku/ch-1.raku | 19 +++++++++++++++++++ stats/pwc-current.json | 21 ++++++++++++++++++++- stats/pwc-language-breakdown-2019.json | 2 +- stats/pwc-language-breakdown-2020.json | 2 +- stats/pwc-language-breakdown-2021.json | 2 +- stats/pwc-language-breakdown-2022.json | 2 +- stats/pwc-language-breakdown-2023.json | 2 +- stats/pwc-language-breakdown-2024.json | 2 +- stats/pwc-language-breakdown-2025.json | 8 ++++---- stats/pwc-language-breakdown-summary.json | 6 +++--- stats/pwc-leaders.json | 8 ++++---- stats/pwc-summary-1-30.json | 2 +- stats/pwc-summary-121-150.json | 2 +- stats/pwc-summary-151-180.json | 2 +- stats/pwc-summary-181-210.json | 6 +++--- stats/pwc-summary-211-240.json | 2 +- stats/pwc-summary-241-270.json | 2 +- stats/pwc-summary-271-300.json | 2 +- stats/pwc-summary-301-330.json | 2 +- stats/pwc-summary-31-60.json | 2 +- stats/pwc-summary-61-90.json | 2 +- stats/pwc-summary-91-120.json | 2 +- stats/pwc-summary.json | 8 ++++---- stats/pwc-yearly-language-summary.json | 8 ++++---- 26 files changed, 122 insertions(+), 39 deletions(-) create mode 100644 challenge-343/mohammad-anwar/perl/ch-1.pl create mode 100644 challenge-343/mohammad-anwar/python/ch-1.py create mode 100644 challenge-343/mohammad-anwar/raku/ch-1.raku diff --git a/challenge-343/mohammad-anwar/perl/ch-1.pl b/challenge-343/mohammad-anwar/perl/ch-1.pl new file mode 100644 index 0000000000..c704bc87b6 --- /dev/null +++ b/challenge-343/mohammad-anwar/perl/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use List::Util qw/min/; + +my @examples = ( + { input => [4, 2, -1, 3, -2], exp => 1 }, + { input => [-5, 5, -3, 3, -1, 1], exp => 1 }, + { input => [7, -3, 0, 2, -8], exp => 0 }, + { input => [-2, -5, -1, -8], exp => 1 }, + { input => [-2, 2, -4, 4, -1, 1], exp => 1 }, +); + +foreach (@examples) { + is(zero_friend($_->{input}), $_->{exp}); +} + +done_testing; + +sub zero_friend { my ($nums) = @_; return min map abs, @$nums } diff --git a/challenge-343/mohammad-anwar/python/ch-1.py b/challenge-343/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..0fa41ba61f --- /dev/null +++ b/challenge-343/mohammad-anwar/python/ch-1.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import unittest + +def zero_friend(nums): + return min(map(abs, nums)) + +class TestZeroFriend(unittest.TestCase): + def test_examples(self): + examples = [ + {'input': [4, 2, -1, 3, -2], 'exp': 1}, + {'input': [-5, 5, -3, 3, -1, 1], 'exp': 1}, + {'input': [7, -3, 0, 2, -8], 'exp': 0}, + {'input': [-2, -5, -1, -8], 'exp': 1}, + {'input': [-2, 2, -4, 4, -1, 1], 'exp': 1}, + ] + + for example in examples: + with self.subTest(input=example['input']): + self.assertEqual(zero_friend(example['input']), example['exp']) + +if __name__ == '__main__': + unittest.main() diff --git a/challenge-343/mohammad-anwar/raku/ch-1.raku b/challenge-343/mohammad-anwar/raku/ch-1.raku new file mode 100644 index 0000000000..5a9aaf94bd --- /dev/null +++ b/challenge-343/mohammad-anwar/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +use Test; + +my @examples = ( + { input => [4, 2, -1, 3, -2], exp => 1 }, + { input => [-5, 5, -3, 3, -1, 1], exp => 1 }, + { input => [7, -3, 0, 2, -8], exp => 0 }, + { input => [-2, -5, -1, -8], exp => 1 }, + { input => [-2, 2, -4, 4, -1, 1], exp => 1 }, +); + +for @examples -> %example { + is(zero_friend(%example), %example); +} + +done-testing; + +sub zero_friend($nums) { return min $nums.map(&abs); } diff --git a/stats/pwc-current.json b/stats/pwc-current.json index ac6a443ce2..b60d715366 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -82,6 +82,20 @@ "id" : "Matthias Muth", "name" : "Matthias Muth" }, + { + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ] + ], + "id" : "Mohammad Sajid Anwar", + "name" : "Mohammad Sajid Anwar" + }, { "data" : [ [ @@ -181,6 +195,11 @@ "name" : "Matthias Muth", "y" : 3 }, + { + "drilldown" : "Mohammad Sajid Anwar", + "name" : "Mohammad Sajid Anwar", + "y" : 2 + }, { "drilldown" : "Packy Anderson", "name" : "Packy Anderson", @@ -201,7 +220,7 @@ } ], "subtitle" : { - "text" : "[Champions: 10] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 11] Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge - 343" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 409b44eb7d..97d2ad7235 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-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index 14f50b04f2..db05720640 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-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index 2d2931b807..e6f9c8f646 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-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 115b592487..d99ba15986 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-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index c0b70cbfbc..29cc7d4ab7 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-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index aa12d6e20a..d6a6f0b301 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-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index aae1ab37aa..3acee9283a 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 18 + 19 ], [ "Raku", - 4 + 5 ], [ "Blog", @@ -763,7 +763,7 @@ { "drilldown" : "343", "name" : "343", - "y" : 28 + "y" : 30 }, { "drilldown" : "342", @@ -970,7 +970,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 851f463fd5..1a66c3b339 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,11 +10,11 @@ "data" : [ [ "Perl", - 17663 + 17664 ], [ "Raku", - 9800 + 9801 ], [ "Blog", @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-10-14 08:39:32 GMT" + "text" : "Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index 018c9d82c7..04819fe064 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -480,11 +480,11 @@ "data" : [ [ "Perl", - 175 + 176 ], [ "Raku", - 108 + 109 ], [ "Blog", @@ -947,7 +947,7 @@ { "drilldown" : "Mohammad Sajid Anwar", "name" : "31: Mohammad Sajid Anwar", - "y" : 728 + "y" : 732 }, { "drilldown" : "Robert Ransbottom", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index 67ec96fdae..a2ac2c48e1 100644 --- a/stats/pwc-summary-1-30.json +++ b/stats/pwc-summary-1-30.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 0f41b0d44c..6e2e56d984 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-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 254cacf23d..3f39b233f5 100644 --- a/stats/pwc-summary-151-180.json +++ b/stats/pwc-summary-151-180.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 c8be90274b..28efa4906f 100644 --- a/stats/pwc-summary-181-210.json +++ b/stats/pwc-summary-181-210.json @@ -28,7 +28,7 @@ 0, 0, 1, - 175, + 176, 0, 0, 40, @@ -63,7 +63,7 @@ 2, 0, 0, - 108, + 109, 1, 10, 40, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 d732ec7a58..bd71e464d6 100644 --- a/stats/pwc-summary-211-240.json +++ b/stats/pwc-summary-211-240.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 8fa57e4e58..ca2c32857e 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 9b7aef0796..1badcbee84 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 f0bfae0b53..d7b2541ce2 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -109,7 +109,7 @@ } ], "subtitle" : { - "text" : "[Champions: 28] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 28] Last updated at 2025-10-14 09:00:54 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 9f28522df4..813ca69f82 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-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 12bb7e5467..361f475f70 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-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 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 1cd2223be9..ce639f3bd8 100644 --- a/stats/pwc-summary-91-120.json +++ b/stats/pwc-summary-91-120.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index 1943b1ebb5..d7b4120b06 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -208,7 +208,7 @@ 0, 0, 1, - 109, + 110, 0, 0, 20, @@ -397,8 +397,8 @@ 6, 0, 0, - 9, 1, + 9, 0, 104, 0, @@ -541,7 +541,7 @@ 1, 0, 0, - 67, + 68, 1, 5, 20, @@ -1009,7 +1009,7 @@ } ], "subtitle" : { - "text" : "[Champions: 328] Last updated at 2025-10-14 08:39:32 GMT" + "text" : "[Champions: 328] Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-yearly-language-summary.json b/stats/pwc-yearly-language-summary.json index 71d4228ab4..39e2747721 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 1886 + 1887 ], [ "Raku", - 924 + 925 ], [ "Blog", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 3552 + "y" : 3554 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 08:39:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:00:54 GMT" }, "title" : { "text" : "The Weekly Challenge Language" -- cgit From fcc99a10bc41e4671d3e40831aae5b49198a02ca Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Tue, 14 Oct 2025 09:10:38 +0000 Subject: w343 - Task 1 & 2 (Perl) --- challenge-343/perlboy1967/perl/ch1.pl | 44 +++++++++++++++++++ challenge-343/perlboy1967/perl/ch2.pl | 79 +++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100755 challenge-343/perlboy1967/perl/ch1.pl create mode 100755 challenge-343/perlboy1967/perl/ch2.pl diff --git a/challenge-343/perlboy1967/perl/ch1.pl b/challenge-343/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..39c495e03b --- /dev/null +++ b/challenge-343/perlboy1967/perl/ch1.pl @@ -0,0 +1,44 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Zero Friend +Submitted by: Mohammad Sajid Anwar + +You are given a list of numbers. + +Find the number that is closest to zero and return its distance to zero. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(min); +use List::MoreUtils qw(any); + +sub zeroFriendMap (@ints) { + min map { abs($_) } @ints; +} + +sub zeroFriend (@ints) { + my $m; + any { $m = min($m // (),abs($_)); $_ == 0 } @ints; + return $m; +} + +is(zeroFriend(4,2,-1,3,-2),1,'Example 1'); +is(zeroFriend(-5,5,-3,3,-1,1),1,'Example 2'); +is(zeroFriend(7,-3,0,2,-8),0,'Example 3'); +is(zeroFriend(-2,-5,-1,-8),1,'Example 4'); +is(zeroFriend(-2,2,-4,4,-1,1),1,'Example 5'); + +is(zeroFriend((0) x 100_000),0,'Own example 1'); +is(zeroFriend(1 .. 1000,0,1 .. 1000),0,'Own example 2'); +is(zeroFriend((1 .. 2000,0)),0,'Own example 3'); + +done_testing; diff --git a/challenge-343/perlboy1967/perl/ch2.pl b/challenge-343/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..2f049d4ce7 --- /dev/null +++ b/challenge-343/perlboy1967/perl/ch2.pl @@ -0,0 +1,79 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Champion Team +Submitted by: Mohammad Sajid Anwar + +You have n teams in a tournament. A matrix grid tells you which team is stronger +between any two teams: + +|| If grid[i][j] == 1, then team i is stronger than team j +|| If grid[i][j] == 0, then team j is stronger than team i + +Find the champion team - the one with most wins, or if there is no single such +team, the strongest of the teams with most wins. (You may assume that there is a +definite answer.) + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(sum max); + +sub championTeam (@grid) { + my %w; + + # Process wins against teams + for (0 .. $#grid) { + push(@{$w{sum(@{$grid[$_]})}},$_); + } + + # Get max scoring team(s) + my @w = @{$w{max(keys(%w))}}; + + # One winning team? Return it! + return $w[0] if scalar @w == 1; + + # Multiple best scoring teams, find the best one + my %uw = map { (sum(@{$grid[$_]}[@w]),$_) } @w; + return $uw{max keys %uw}; +} + +is(championTeam([0,1,1], + [0,0,1], + [0,0,0]), + 0,q{Example 1}); +is(championTeam([0,1,0,0], + [0,0,0,0], + [1,1,0,0], + [1,1,1,0]), + 3,q{Example 2}); +is(championTeam([0,1,0,1], + [0,0,1,1], + [1,0,0,0], + [0,0,1,0]), + 0,q{Example 3}); +is(championTeam([0,1,1], + [0,0,0], + [0,1,0]), + 0,q{Example 4}); +is(championTeam([0,0,0,0,0], + [1,0,0,0,0], + [1,1,0,1,1], + [1,1,0,0,0], + [1,1,0,1,0]), + 2,q{Example 5}); +is(championTeam([0,1,1,1,0,0], + [0,0,1,0,1,1], + [0,0,0,0,1,1], + [0,1,1,0,1,1], + [1,0,0,0,0,0], + [1,0,0,0,1,0]), + 3,q{Matthias Muth's test}); +done_testing; -- cgit From 7f402e9d0ada4506d06824aeb010ef78cef2e7c2 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 14 Oct 2025 10:16:20 +0100 Subject: - Added solutions by Niels van Dijke. --- challenge-343/perlboy1967/perl/ch-1.pl | 44 +++++++++++++++++ challenge-343/perlboy1967/perl/ch-2.pl | 79 +++++++++++++++++++++++++++++++ challenge-343/perlboy1967/perl/ch1.pl | 44 ----------------- challenge-343/perlboy1967/perl/ch2.pl | 79 ------------------------------- stats/pwc-current.json | 17 ++++++- stats/pwc-language-breakdown-2019.json | 2 +- stats/pwc-language-breakdown-2020.json | 2 +- stats/pwc-language-breakdown-2021.json | 2 +- stats/pwc-language-breakdown-2022.json | 2 +- stats/pwc-language-breakdown-2023.json | 2 +- stats/pwc-language-breakdown-2024.json | 2 +- stats/pwc-language-breakdown-2025.json | 6 +-- stats/pwc-language-breakdown-summary.json | 4 +- stats/pwc-leaders.json | 6 +-- stats/pwc-summary-1-30.json | 2 +- stats/pwc-summary-121-150.json | 2 +- stats/pwc-summary-151-180.json | 2 +- stats/pwc-summary-181-210.json | 4 +- stats/pwc-summary-211-240.json | 2 +- stats/pwc-summary-241-270.json | 2 +- stats/pwc-summary-271-300.json | 2 +- stats/pwc-summary-301-330.json | 2 +- stats/pwc-summary-31-60.json | 2 +- stats/pwc-summary-61-90.json | 2 +- stats/pwc-summary-91-120.json | 2 +- stats/pwc-summary.json | 6 +-- stats/pwc-yearly-language-summary.json | 6 +-- 27 files changed, 171 insertions(+), 156 deletions(-) create mode 100755 challenge-343/perlboy1967/perl/ch-1.pl create mode 100755 challenge-343/perlboy1967/perl/ch-2.pl delete mode 100755 challenge-343/perlboy1967/perl/ch1.pl delete mode 100755 challenge-343/perlboy1967/perl/ch2.pl diff --git a/challenge-343/perlboy1967/perl/ch-1.pl b/challenge-343/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..39c495e03b --- /dev/null +++ b/challenge-343/perlboy1967/perl/ch-1.pl @@ -0,0 +1,44 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Zero Friend +Submitted by: Mohammad Sajid Anwar + +You are given a list of numbers. + +Find the number that is closest to zero and return its distance to zero. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(min); +use List::MoreUtils qw(any); + +sub zeroFriendMap (@ints) { + min map { abs($_) } @ints; +} + +sub zeroFriend (@ints) { + my $m; + any { $m = min($m // (),abs($_)); $_ == 0 } @ints; + return $m; +} + +is(zeroFriend(4,2,-1,3,-2),1,'Example 1'); +is(zeroFriend(-5,5,-3,3,-1,1),1,'Example 2'); +is(zeroFriend(7,-3,0,2,-8),0,'Example 3'); +is(zeroFriend(-2,-5,-1,-8),1,'Example 4'); +is(zeroFriend(-2,2,-4,4,-1,1),1,'Example 5'); + +is(zeroFriend((0) x 100_000),0,'Own example 1'); +is(zeroFriend(1 .. 1000,0,1 .. 1000),0,'Own example 2'); +is(zeroFriend((1 .. 2000,0)),0,'Own example 3'); + +done_testing; diff --git a/challenge-343/perlboy1967/perl/ch-2.pl b/challenge-343/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..2f049d4ce7 --- /dev/null +++ b/challenge-343/perlboy1967/perl/ch-2.pl @@ -0,0 +1,79 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Champion Team +Submitted by: Mohammad Sajid Anwar + +You have n teams in a tournament. A matrix grid tells you which team is stronger +between any two teams: + +|| If grid[i][j] == 1, then team i is stronger than team j +|| If grid[i][j] == 0, then team j is stronger than team i + +Find the champion team - the one with most wins, or if there is no single such +team, the strongest of the teams with most wins. (You may assume that there is a +definite answer.) + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(sum max); + +sub championTeam (@grid) { + my %w; + + # Process wins against teams + for (0 .. $#grid) { + push(@{$w{sum(@{$grid[$_]})}},$_); + } + + # Get max scoring team(s) + my @w = @{$w{max(keys(%w))}}; + + # One winning team? Return it! + return $w[0] if scalar @w == 1; + + # Multiple best scoring teams, find the best one + my %uw = map { (sum(@{$grid[$_]}[@w]),$_) } @w; + return $uw{max keys %uw}; +} + +is(championTeam([0,1,1], + [0,0,1], + [0,0,0]), + 0,q{Example 1}); +is(championTeam([0,1,0,0], + [0,0,0,0], + [1,1,0,0], + [1,1,1,0]), + 3,q{Example 2}); +is(championTeam([0,1,0,1], + [0,0,1,1], + [1,0,0,0], + [0,0,1,0]), + 0,q{Example 3}); +is(championTeam([0,1,1], + [0,0,0], + [0,1,0]), + 0,q{Example 4}); +is(championTeam([0,0,0,0,0], + [1,0,0,0,0], + [1,1,0,1,1], + [1,1,0,0,0], + [1,1,0,1,0]), + 2,q{Example 5}); +is(championTeam([0,1,1,1,0,0], + [0,0,1,0,1,1], + [0,0,0,0,1,1], + [0,1,1,0,1,1], + [1,0,0,0,0,0], + [1,0,0,0,1,0]), + 3,q{Matthias Muth's test}); +done_testing; diff --git a/challenge-343/perlboy1967/perl/ch1.pl b/challenge-343/perlboy1967/perl/ch1.pl deleted file mode 100755 index 39c495e03b..0000000000 --- a/challenge-343/perlboy1967/perl/ch1.pl +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/perl - -=pod - -L - -Author: Niels 'PerlBoy' van Dijke - -Task 1: Zero Friend -Submitted by: Mohammad Sajid Anwar - -You are given a list of numbers. - -Find the number that is closest to zero and return its distance to zero. - -=cut - -use Test2::V0 qw(-no_srand); -use exact 'v5.32', -signatures; - -use List::Util qw(min); -use List::MoreUtils qw(any); - -sub zeroFriendMap (@ints) { - min map { abs($_) } @ints; -} - -sub zeroFriend (@ints) { - my $m; - any { $m = min($m // (),abs($_)); $_ == 0 } @ints; - return $m; -} - -is(zeroFriend(4,2,-1,3,-2),1,'Example 1'); -is(zeroFriend(-5,5,-3,3,-1,1),1,'Example 2'); -is(zeroFriend(7,-3,0,2,-8),0,'Example 3'); -is(zeroFriend(-2,-5,-1,-8),1,'Example 4'); -is(zeroFriend(-2,2,-4,4,-1,1),1,'Example 5'); - -is(zeroFriend((0) x 100_000),0,'Own example 1'); -is(zeroFriend(1 .. 1000,0,1 .. 1000),0,'Own example 2'); -is(zeroFriend((1 .. 2000,0)),0,'Own example 3'); - -done_testing; diff --git a/challenge-343/perlboy1967/perl/ch2.pl b/challenge-343/perlboy1967/perl/ch2.pl deleted file mode 100755 index 2f049d4ce7..0000000000 --- a/challenge-343/perlboy1967/perl/ch2.pl +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/perl - -=pod - -L - -Author: Niels 'PerlBoy' van Dijke - -Task 2: Champion Team -Submitted by: Mohammad Sajid Anwar - -You have n teams in a tournament. A matrix grid tells you which team is stronger -between any two teams: - -|| If grid[i][j] == 1, then team i is stronger than team j -|| If grid[i][j] == 0, then team j is stronger than team i - -Find the champion team - the one with most wins, or if there is no single such -team, the strongest of the teams with most wins. (You may assume that there is a -definite answer.) - -=cut - -use Test2::V0 qw(-no_srand); -use exact 'v5.32', -signatures; - -use List::Util qw(sum max); - -sub championTeam (@grid) { - my %w; - - # Process wins against teams - for (0 .. $#grid) { - push(@{$w{sum(@{$grid[$_]})}},$_); - } - - # Get max scoring team(s) - my @w = @{$w{max(keys(%w))}}; - - # One winning team? Return it! - return $w[0] if scalar @w == 1; - - # Multiple best scoring teams, find the best one - my %uw = map { (sum(@{$grid[$_]}[@w]),$_) } @w; - return $uw{max keys %uw}; -} - -is(championTeam([0,1,1], - [0,0,1], - [0,0,0]), - 0,q{Example 1}); -is(championTeam([0,1,0,0], - [0,0,0,0], - [1,1,0,0], - [1,1,1,0]), - 3,q{Example 2}); -is(championTeam([0,1,0,1], - [0,0,1,1], - [1,0,0,0], - [0,0,1,0]), - 0,q{Example 3}); -is(championTeam([0,1,1], - [0,0,0], - [0,1,0]), - 0,q{Example 4}); -is(championTeam([0,0,0,0,0], - [1,0,0,0,0], - [1,1,0,1,1], - [1,1,0,0,0], - [1,1,0,1,0]), - 2,q{Example 5}); -is(championTeam([0,1,1,1,0,0], - [0,0,1,0,1,1], - [0,0,0,0,1,1], - [0,1,1,0,1,1], - [1,0,0,0,0,0], - [1,0,0,0,1,0]), - 3,q{Matthias Muth's test}); -done_testing; diff --git a/stats/pwc-current.json b/stats/pwc-current.json index b60d715366..2d79786669 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -96,6 +96,16 @@ "id" : "Mohammad Sajid Anwar", "name" : "Mohammad Sajid Anwar" }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Niels van Dijke", + "name" : "Niels van Dijke" + }, { "data" : [ [ @@ -200,6 +210,11 @@ "name" : "Mohammad Sajid Anwar", "y" : 2 }, + { + "drilldown" : "Niels van Dijke", + "name" : "Niels van Dijke", + "y" : 2 + }, { "drilldown" : "Packy Anderson", "name" : "Packy Anderson", @@ -220,7 +235,7 @@ } ], "subtitle" : { - "text" : "[Champions: 11] Last updated at 2025-10-14 09:00:54 GMT" + "text" : "[Champions: 12] Last updated at 2025-10-14 09:16:16 GMT" }, "title" : { "text" : "The Weekly Challenge - 343" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 97d2ad7235..04afa289db 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-10-14 09:00:54 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:16:16 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index db05720640..17c238ed0a 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-10-14 09:00:54 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:16:16 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index e6f9c8f646..3469afa74d 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-10-14 09:00:54 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:16:16 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index d99ba15986..dd6fd9fd6b 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-10-14 09:00:54 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:16:16 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index 29cc7d4ab7..7bbba9e0ef 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-10-14 09:00:54 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-14 09:16:16 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index d6a6f0b301..bcef9822fe 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-10-14 09:00:54 GMT" + "text" : "Click the columns to drilldown the lang