From 0851945c8b5a779ce1794e69452e6540c4033c23 Mon Sep 17 00:00:00 2001 From: rir Date: Wed, 7 May 2025 00:54:31 -0400 Subject: 320 --- challenge-320/0rir/raku/ch-1.raku | 40 +++++++++++++++++++++++++++++++++++++++ challenge-320/0rir/raku/ch-2.raku | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 challenge-320/0rir/raku/ch-1.raku create mode 100644 challenge-320/0rir/raku/ch-2.raku diff --git a/challenge-320/0rir/raku/ch-1.raku b/challenge-320/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..c8fc36a119 --- /dev/null +++ b/challenge-320/0rir/raku/ch-1.raku @@ -0,0 +1,40 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ +use v6.d; +use Test; + +=begin comment +320-Task 1: Maximum Count Submitted by: Mohammad Sajid Anwar +You are given an array of integers. + +Write a script to return the maximum between the number of positive and negative integers. Zero is neither positive nor negative. + + +Example 1 +Input: @ints = (-3, -2, -1, 1, 2, 3) +Output: 3 + +… +=end comment + +my @Test = + # in exp + (-3, -2, -1, 1, 2, 3), 3, + (-2, -1, 0, 0, 1), 2, + (1, 2, 3, 4), 4, + (0,0), 0, + (9,), 1, + (-9,), 1, +; +plan @Test ÷ 2; + +sub task( @a) { max +@a.grep( * > 0), +@a.grep( * < 0) } + +for @Test -> @in, $exp { + is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()"; +} +done-testing; + +my @int = -3, -2, -1, 1, 2, 3; + +say qq{\nInput: @int = @int.raku()\nOutput: }, task @int; diff --git a/challenge-320/0rir/raku/ch-2.raku b/challenge-320/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..e8d6f180c4 --- /dev/null +++ b/challenge-320/0rir/raku/ch-2.raku @@ -0,0 +1,38 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ +use v6.d; +use Test; + +=begin comment +320-2: Sum Difference Submitted by: Mohammad Sajid Anwar +You are given an array of positive integers. + +Write a script to return the absolute difference between digit sum and element sum of the given array. + +Example 1 +Input: @ints = (1, 23, 4, 5) +Output: 18 +… +=end comment + +my @Test = + # in exp + (1, 23, 4, 5), 18, + (1, 2, 3, 4, 5), 0, + (1, 2, 34), 27, + (), 0, + (12,), 9, +; + +plan @Test ÷ 2; + +sub task( @a) { ( @a.sum - @a.join.comb.sum ).abs } + +for @Test -> @in, $exp { + is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()"; +} +done-testing; + +my @int = 1, 23, 4, 5; + +say qq{\nInput: @int = @int.raku()\nOutput: }, task( @int); -- cgit From 860bb0241d1dfe6912a015d534d7ab7f33c72102 Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Thu, 8 May 2025 21:28:05 -0700 Subject: Robbie Hatley's solutions, in Perl, for The Weekly Challenge #320. --- challenge-320/robbie-hatley/blog.txt | 1 + challenge-320/robbie-hatley/perl/ch-1.pl | 80 ++++++++++++++++++++++++++++++++ challenge-320/robbie-hatley/perl/ch-2.pl | 80 ++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 challenge-320/robbie-hatley/blog.txt create mode 100755 challenge-320/robbie-hatley/perl/ch-1.pl create mode 100755 challenge-320/robbie-hatley/perl/ch-2.pl diff --git a/challenge-320/robbie-hatley/blog.txt b/challenge-320/robbie-hatley/blog.txt new file mode 100644 index 0000000000..4c1ffa7cb5 --- /dev/null +++ b/challenge-320/robbie-hatley/blog.txt @@ -0,0 +1 @@ +https://hatley-software.blogspot.com/2025/05/robbie-hatleys-solutions-in-perl-for.html diff --git a/challenge-320/robbie-hatley/perl/ch-1.pl b/challenge-320/robbie-hatley/perl/ch-1.pl new file mode 100755 index 0000000000..ea0b53b2ce --- /dev/null +++ b/challenge-320/robbie-hatley/perl/ch-1.pl @@ -0,0 +1,80 @@ +#!/usr/bin/env perl + +=pod + +-------------------------------------------------------------------------------------------------------------- +TITLE AND ATTRIBUTION: +Solutions in Perl for The Weekly Challenge 320-1, +written by Robbie Hatley on Mon May 05, 2025. + +-------------------------------------------------------------------------------------------------------------- +PROBLEM DESCRIPTION: +Task 320-1: Maximum Count +Submitted by: Mohammad Sajid Anwar +You are given an array of integers. Write a script to return the +maximum between the number of positive and negative integers. +Zero is neither positive nor negative. + +Example #1: +Input: @ints = (-3, -2, -1, 1, 2, 3) +Output: 3 +There are 3 positive integers. +There are 3 negative integers. +The maximum between 3 and 3 is 3. + +Example #2: +Input: @ints = (-2, -1, 0, 0, 1) +Output: 2 +There are 1 positive integers. +There are 2 negative integers. +The maximum between 2 and 1 is 2. + +Example #3: +Input: @ints = (1, 2, 3, 4) +Output: 4 +There are 4 positive integers. +There are 0 negative integers. +The maximum between 4 and 0 is 4. + +-------------------------------------------------------------------------------------------------------------- +PROBLEM NOTES: +To solve this problem, I'll grep for negatives, and grep for positives, and return the max between the scalars +of those two lists. + +-------------------------------------------------------------------------------------------------------------- +IO NOTES: +Input is via either built-in variables or via @ARGV. If using @ARGV, provide one argument which must be a +single-quoted array of arrays of integers, in proper Perl syntax, like so: + +./ch-1.pl '([-2,-1,0,1,2,3],[-1,5,-37,-42,3,-89,-13,54,-8,-17])' + +Output is to STDOUT and will be each input followed by the corresponding output. + +=cut + +# ------------------------------------------------------------------------------------------------------------ +# PRAGMAS, MODULES, AND SUBS: + + use v5.36; + use List::Util 'max'; + # What is max(count of neg. ints, count of pos. ints) in an array? + sub mc($aref){max(scalar(grep{$_<0}@$aref),scalar(grep{$_>0}@$aref))} + +# ------------------------------------------------------------------------------------------------------------ +# INPUTS: +my @arrays = @ARGV ? eval($ARGV[0]) : +( + [-3, -2, -1, 1, 2, 3], # 3 + [-2, -1, 0, 0, 1], # 2 + [1, 2, 3, 4], # 4 +); + +# ------------------------------------------------------------------------------------------------------------ +# MAIN BODY OF PROGRAM: +$"=', '; +for my $aref (@arrays) { + say ''; + say "Array = (@$aref)"; + my $mc = mc($aref); + say "Max Count = $mc"; +} diff --git a/challenge-320/robbie-hatley/perl/ch-2.pl b/challenge-320/robbie-hatley/perl/ch-2.pl new file mode 100755 index 0000000000..afc37db4c5 --- /dev/null +++ b/challenge-320/robbie-hatley/perl/ch-2.pl @@ -0,0 +1,80 @@ +#!/usr/bin/env perl + +=pod + +-------------------------------------------------------------------------------------------------------------- +TITLE AND ATTRIBUTION: +Solutions in Perl for The Weekly Challenge ###-2, +written by Robbie Hatley on Mon May 05, 2025. + +-------------------------------------------------------------------------------------------------------------- +PROBLEM DESCRIPTION: +Task 320-2: Sum Difference +Submitted by: Mohammad Sajid Anwar +You are given an array of positive integers. Write a script to +return the absolute difference between digit sum and element sum +of the given array. + +Example #1: +Input: @ints = (1, 23, 4, 5) +Output: 18 +Element sum: 1 + 23 + 4 + 5 => 33 +Digit sum: 1 + 2 + 3 + 4 + 5 => 15 +Absolute difference: | 33 - 15 | => 18 + +Example #2: +Input: @ints = (1, 2, 3, 4, 5) +Output: 0 +Element sum: 1 + 2 + 3 + 4 + 5 => 15 +Digit sum: 1 + 2 + 3 + 4 + 5 => 15 +Absolute difference: | 15 - 15 | => 0 + +Example #3: +Input: @ints = (1, 2, 34) +Output: 27 +Element sum: 1 + 2 + 34 => 37 +Digit sum: 1 + 2 + 3 + 4 => 10 +Absolute difference: | 37 - 10 | => 27 + +-------------------------------------------------------------------------------------------------------------- +PROBLEM NOTES: +To solve this problem, I'll split-and-sum the digits to get the digit sum, then sum the ints, then return the +absolute value of the difference between those two sums. + +-------------------------------------------------------------------------------------------------------------- +IO NOTES: +Input is via either built-in variables or via @ARGV. If using @ARGV, provide one argument which must be a +single-quoted array of arrays of positive integers, in proper Perl syntax, like so: + +./ch-2.pl '([1,2,3,4,5],[1,2,3,44,55])' + +Output is to STDOUT and will be each input followed by the corresponding output. + +=cut + +# ------------------------------------------------------------------------------------------------------------ +# PRAGMAS, MODULES, AND SUBS: + + use v5.36; + use List::Util 'sum0'; + # Abs(sum(elements)-sum(digits)): + sub sd($aref){abs(sum0(@$aref)-sum0(map{split//,$_}@$aref))} + +# ------------------------------------------------------------------------------------------------------------ +# INPUTS: +my @arrays = @ARGV ? eval($ARGV[0]) : +( + [1, 23, 4, 5], # 18 + [1, 2, 3, 4, 5], # 0 + [1, 2, 34], # 27 +); + +# ------------------------------------------------------------------------------------------------------------ +# MAIN BODY OF PROGRAM: +$"=', '; +for my $aref (@arrays) { + say ''; + say "Array = (@$aref)"; + my $sd = sd($aref); + say "Absolute value of (element sum - digit sum) = $sd"; +} -- cgit From ec816fc38b42800a00f6d5b57c80cbae38f14958 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Fri, 9 May 2025 08:48:24 +0200 Subject: PWC 320 Task 1 done in Raku Task 2 in Raku done --- challenge-320/luca-ferrari/blog-1.txt | 1 + challenge-320/luca-ferrari/blog-2.txt | 1 + challenge-320/luca-ferrari/raku/ch-1.raku | 12 ++++++++++++ challenge-320/luca-ferrari/raku/ch-2.raku | 14 ++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 challenge-320/luca-ferrari/blog-1.txt create mode 100644 challenge-320/luca-ferrari/blog-2.txt create mode 100644 challenge-320/luca-ferrari/raku/ch-1.raku create mode 100644 challenge-320/luca-ferrari/raku/ch-2.raku diff --git a/challenge-320/luca-ferrari/blog-1.txt b/challenge-320/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..a023e6fefb --- /dev/null +++ b/challenge-320/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/05/09/PerlWeeklyChallenge320.html#task1 diff --git a/challenge-320/luca-ferrari/blog-2.txt b/challenge-320/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..4e61a124dd --- /dev/null +++ b/challenge-320/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/05/09/PerlWeeklyChallenge320.html#task2 diff --git a/challenge-320/luca-ferrari/raku/ch-1.raku b/challenge-320/luca-ferrari/raku/ch-1.raku new file mode 100644 index 0000000000..79d8802cf0 --- /dev/null +++ b/challenge-320/luca-ferrari/raku/ch-1.raku @@ -0,0 +1,12 @@ +#!raku + +# +# Perl Weekly Challenge 320 +# Task 1 +# +# See +# + +sub MAIN( *@numbers where { @numbers.grep( * ~~ Int ).elems == @numbers.elems }) { + ( @numbers.grep( *.Int <= 0 ).elems, @numbers.grep( *.Int >= 0 ).elems ).max.say; +} diff --git a/challenge-320/luca-ferrari/raku/ch-2.raku b/challenge-320/luca-ferrari/raku/ch-2.raku new file mode 100644 index 0000000000..527c6da755 --- /dev/null +++ b/challenge-320/luca-ferrari/raku/ch-2.raku @@ -0,0 +1,14 @@ +#!raku + +# +# Perl Weekly Challenge 320 +# Task 2 +# +# See +# + +sub MAIN( *@numbers where { @numbers.grep( *.Int > 0 ).elems == @numbers.elems } ) { + my $sum = @numbers.sum; + my $digit-sum = @numbers.map( *.comb ).sum; + say abs( $digit-sum - $sum ); +} -- cgit From e31f7c642967d7d69a079a00a0ff5652978c4785 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 6 May 2025 15:22:18 +0200 Subject: Solution to task 1 --- challenge-320/jo-37/perl/ch-1.pl | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 challenge-320/jo-37/perl/ch-1.pl diff --git a/challenge-320/jo-37/perl/ch-1.pl b/challenge-320/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..76527f952f --- /dev/null +++ b/challenge-320/jo-37/perl/ch-1.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +use v5.26; +use Test2::V0 qw(!float -no_srand); +use Test2::Tools::Subtest 'subtest_streamed'; +use Getopt::Long; +use experimental 'signatures'; + +use PDL; + +### Options and Arguments + +my ($tests, $examples, $verbose); +GetOptions( + 'examples!' => \$examples, + 'tests!' => \$tests, + 'verbose!' => \$verbose, +) or usage(); + +run_tests($examples, $tests); # tests do not return + +usage() unless @ARGV; + +sub usage { + die <<~EOS; + $0 - maximum count + + usage: $0 [-examples] [-tests] [--] [I...] + + -examples + run the examples from the challenge + + -tests + run some tests + + I... + list of integers + + EOS +} + + +### Input and Output + +say max_count(@ARGV); + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2025/05/09/ch-320.html#task-1 + + +sub max_count { + my $s = long(@_)->clip(-1, 1); + (sum(abs $s) + abs(sum $s)) / 2; +} + + +### Examples and Tests + +sub run_tests ($examples, $tests) { + return unless $examples || $tests; + + state sub run_example ($args, $expected, $name) { + my $result = max_count(@$args); + is $result, $expected, + "$name: (@$args) -> $expected"; + } + + plan 2; + + $examples ? subtest_streamed(examples => sub { + my @examples = ( + [[-3, -2, -1, 1, 2, 3], 3, 'example 1'], + [[-2, -1, 0, 0, 1], 2, 'example 2'], + [[1, 2, 3, 4], 4, 'example 3'], + ); + plan scalar @examples; + for (@examples) { + run_example @$_; + } + }) : pass 'skip examples'; + + $tests ? subtest_streamed(tests => sub { + plan 3; + is max_count(0, 0, 0), 0, 'zeroes only'; + is max_count(-1, -2, -3), 3, 'negative only'; + is max_count(0 .. 99, -99 .. 0), 99, 'ninty nine'; + }) : pass 'skip tests'; + + exit; +} -- cgit From c57441b0d0365243d22b32011178deda7677df59 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 6 May 2025 15:22:33 +0200 Subject: Solution to task 2 --- challenge-320/jo-37/perl/ch-2.pl | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 challenge-320/jo-37/perl/ch-2.pl diff --git a/challenge-320/jo-37/perl/ch-2.pl b/challenge-320/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..7ad04bbbc6 --- /dev/null +++ b/challenge-320/jo-37/perl/ch-2.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl + +use v5.26; +use Test2::V0 -no_srand; +use Test2::Tools::Subtest 'subtest_streamed'; +use Getopt::Long; +use experimental 'signatures'; + +use Math::Prime::Util qw(vecsum todigits); + + +### Options and Arguments + +my ($tests, $examples, $verbose); +GetOptions( + 'examples!' => \$examples, + 'tests!' => \$tests, + 'verbose!' => \$verbose, +) or usage(); + +run_tests($examples, $tests); # tests do not return + +usage() unless @ARGV; + +sub usage { + die <<~EOS; + $0 - sum difference + + usage: $0 [-examples] [-tests] [N...] + + -examples + run the examples from the challenge + + -tests + run some tests + + N... + list of positive integers + + EOS +} + + +### Input and Output + +say sum_diff(@ARGV); + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2025/05/09/ch-320.html#task-2 + +use constant BASE => 10; + +sub sum_diff { + vecsum(@_) - vecsum map todigits($_, BASE), @_; +} + + +### Examples and Tests + +sub run_tests ($examples, $tests) { + return unless $examples || $tests; + + state sub run_example ($args, $expected, $name) { + my $result = sum_diff(@$args); + is $result, $expected, + "$name: (@$args) -> $expected"; + } + + plan 2; + + $examples ? subtest_streamed(examples => sub { + my @examples = ( + [[1, 23, 4, 5], 18, 'example 1'], + [[1, 2, 3, 4, 5], 0, 'example 2'], + [[1, 2, 34], 27, 'example 3'], + ); + plan scalar @examples; + for (@examples) { + run_example @$_; + } + }) : pass 'skip examples'; + + $tests ? subtest_streamed(tests => sub { + plan 1; + pass 'no tests'; + }) : pass 'skip tests'; + + exit; +} -- cgit From 69588fd89d5fb3a80722fd987c98d241d87dacc9 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 6 May 2025 15:22:49 +0200 Subject: Blog for challenge 320 --- challenge-320/jo-37/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-320/jo-37/blog.txt diff --git a/challenge-320/jo-37/blog.txt b/challenge-320/jo-37/blog.txt new file mode 100644 index 0000000000..09ad218a47 --- /dev/null +++ b/challenge-320/jo-37/blog.txt @@ -0,0 +1 @@ +https://github.sommrey.de/the-bears-den/2025/05/09/ch-320.html -- cgit From 6f4a054298cc3cfba9364a9f64241fcd070b355d Mon Sep 17 00:00:00 2001 From: Thomas Köhler Date: Fri, 9 May 2025 21:40:01 +0200 Subject: Add solution 320. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Köhler --- challenge-320/jeanluc2020/blog-1.txt | 1 + challenge-320/jeanluc2020/blog-2.txt | 1 + challenge-320/jeanluc2020/perl/ch-1.pl | 72 ++++++++++++++++++++++++++++++++++ challenge-320/jeanluc2020/perl/ch-2.pl | 70 +++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 challenge-320/jeanluc2020/blog-1.txt create mode 100644 challenge-320/jeanluc2020/blog-2.txt create mode 100755 challenge-320/jeanluc2020/perl/ch-1.pl create mode 100755 challenge-320/jeanluc2020/perl/ch-2.pl diff --git a/challenge-320/jeanluc2020/blog-1.txt b/challenge-320/jeanluc2020/blog-1.txt new file mode 100644 index 0000000000..305c891870 --- /dev/null +++ b/challenge-320/jeanluc2020/blog-1.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-320-1.html diff --git a/challenge-320/jeanluc2020/blog-2.txt b/challenge-320/jeanluc2020/blog-2.txt new file mode 100644 index 0000000000..d1550725b1 --- /dev/null +++ b/challenge-320/jeanluc2020/blog-2.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-320-2.html diff --git a/challenge-320/jeanluc2020/perl/ch-1.pl b/challenge-320/jeanluc2020/perl/ch-1.pl new file mode 100755 index 0000000000..113a336843 --- /dev/null +++ b/challenge-320/jeanluc2020/perl/ch-1.pl @@ -0,0 +1,72 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-320/#TASK1 +# +# Task 1: Maximum Count +# ===================== +# +# You are given an array of integers. +# +# Write a script to return the maximum between the number of positive and +# negative integers. Zero is neither positive nor negative. +# +## Example 1 +## +## Input: @ints = (-3, -2, -1, 1, 2, 3) +## Output: 3 +## +## There are 3 positive integers. +## There are 3 negative integers. +## The maximum between 3 and 3 is 3. +# +# +## Example 2 +## +## Input: @ints = (-2, -1, 0, 0, 1) +## Output: 2 +## +## There are 1 positive integers. +## There are 2 negative integers. +## The maximum between 2 and 1 is 2. +# +# +## Example 3 +## +## Input: @ints = (1, 2, 3, 4) +## Output: 4 +## +## There are 4 positive integers. +## There are 0 negative integers. +## The maximum between 4 and 0 is 4. +# +############################################################ +## +## discussion +## +############################################################ +# +# We just count the positive and the negative integers. +# Then we look which of these two numbers is bigger. + +use v5.36; + +maximum_count(-3, -2, -1, 1, 2, 3); +maximum_count(-2, -1, 0, 0, 1); +maximum_count(1, 2, 3, 4); + +sub maximum_count(@ints) { + say "Input: (" . join(", ", @ints) . ")"; + my $neg = 0; + my $pos = 0; + foreach my $elem (@ints) { + if($elem > 0) { + $pos++; + } elsif ( $elem < 0 ) { + $neg++; + } + } + if($neg > $pos) { + say "Output: $neg"; + } else { + say "Output: $pos"; + } +} diff --git a/challenge-320/jeanluc2020/perl/ch-2.pl b/challenge-320/jeanluc2020/perl/ch-2.pl new file mode 100755 index 0000000000..ad575b21db --- /dev/null +++ b/challenge-320/jeanluc2020/perl/ch-2.pl @@ -0,0 +1,70 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-320/#TASK2 +# +# Task 2: Sum Difference +# ====================== +# +# You are given an array of positive integers. +# +# Write a script to return the absolute difference between digit sum and +# element sum of the given array. +# +## Example 1 +## +## Input: @ints = (1, 23, 4, 5) +## Output: 18 +## +## Element sum: 1 + 23 + 4 + 5 => 33 +## Digit sum: 1 + 2 + 3 + 4 + 5 => 15 +## Absolute difference: | 33 - 15 | => 18 +# +# +## Example 2 +## +## Input: @ints = (1, 2, 3, 4, 5) +## Output: 0 +## +## Element sum: 1 + 2 + 3 + 4 + 5 => 15 +## Digit sum: 1 + 2 + 3 + 4 + 5 => 15 +## Absolute difference: | 15 - 15 | => 0 +# +# +## Example 3 +## +## Input: @ints = (1, 2, 34) +## Output: 27 +## +## Element sum: 1 + 2 + 34 => 37 +## Digit sum: 1 + 2 + 3 + 4 => 10 +## Absolute difference: | 37 - 10 | => 27 +# +############################################################ +## +## discussion +## +############################################################ +# +# Looking at each element in the list, we just add it to the element sum. +# Then we split the element into its digits and add all of those to the +# digit sum. In the end, we calculate the absolute difference of these two +# sums for the result. + +use v5.36; + +sum_difference(1, 23, 4, 5); +sum_difference(1, 2, 3, 4, 5); +sum_difference(1, 2, 34); + +sub sum_difference(@ints) { + say "Input: (" . join(", ", @ints) . ")"; + my $elem_sum = 0; + my $digit_sum = 0; + foreach my $elem (@ints) { + $elem_sum += $elem; + my @digits = split //, $elem; + foreach my $digit (@digits) { + $digit_sum += $digit; + } + } + say "Output: " . abs($elem_sum - $digit_sum); +} -- cgit From 50c48267764e47ab045105f6da350d1b233d2bd4 Mon Sep 17 00:00:00 2001 From: Matthias Muth Date: Fri, 9 May 2025 21:50:37 +0200 Subject: Challenge 320 Task 1 and 2 solutions in Perl by Matthias Muth --- challenge-320/matthias-muth/README.md | 251 ++++++++++++++++++------------- challenge-320/matthias-muth/blog.txt | 1 + challenge-320/matthias-muth/perl/ch-1.pl | 56 +++++++ challenge-320/matthias-muth/perl/ch-2.pl | 52 +++++++ 4 files changed, 258 insertions(+), 102 deletions(-) create mode 100644 challenge-320/matthias-muth/blog.txt create mode 100755 challenge-320/matthias-muth/perl/ch-1.pl create mode 100755 challenge-320/matthias-muth/perl/ch-2.pl diff --git a/challenge-320/matthias-muth/README.md b/challenge-320/matthias-muth/README.md index 5103802a85..9953f56187 100644 --- a/challenge-320/matthias-muth/README.md +++ b/challenge-320/matthias-muth/README.md @@ -1,174 +1,221 @@ -# Does 'Weekly' Have a Happy (Vowel) Ending? +# Elegance Makes the Maximum Difference +**Challenge 320 solutions in Perl by Matthias Muth** -**Challenge 319 solutions in Perl by Matthias Muth** +## Task 1: Maximum Count -## Task 1: Word Count - -> You are given a list of words containing alphabetic characters only.
-> Write a script to return the count of words either starting with a vowel or ending with a vowel. +> You are given an array of integers.
+> Write a script to return the maximum between the number of positive and negative integers. Zero is neither positive nor negative. > > **Example 1** > > ```text -> Input: @list = ("unicode", "xml", "raku", "perl") -> Output: 2 -> -> The words are "unicode" and "raku". -> ``` -> -> **Example 2** +> Input: @ints = (-3, -2, -1, 1, 2, 3) +> Output: 3 > -> ```text -> Input: @list = ("the", "weekly", "challenge") +> There are 3 positive integers. +> There are 3 negative integers. +> The maximum between 3 and 3 is 3. +>``` +> +>**Example 2** +> +>```text +> Input: @ints = (-2, -1, 0, 0, 1) > Output: 2 +> +>There are 1 positive integers. +> There are 2 negative integers. +> The maximum between 2 and 1 is 2. > ``` > > **Example 3** > > ```text -> Input: @list = ("perl", "python", "postgres") -> Output: 0 +>Input: @ints = (1, 2, 3, 4) +> Output: 4 +> +> There are 4 positive integers. +>There are 0 negative integers. +> The maximum between 4 and 0 is 4. > ``` -What is a vowel, really?
-Doesn't 'weekly' happily end in a vowel?
-Don't worry (oh, another one!).
-I'm a programmer, so I'm infallible! -And as I have grown up with ASCII, so there can only be one meaning of what a vowel really is.
Here it is. These are The Vowels: +It's a matter of taste: -``` - a e i o u -``` +* Single pass:
+ Go through the list of integers in a loop, + increment one of two counters depending on the number's sign. + Then return the maximum of the two counts. -So please, no [Sunday sermons](https://en.wikipedia.org/wiki/Vowel) about vowels actually being sounds, not letters...
And no discussions about [vowels in Unicode](https://stackoverflow.com/questions/38792789/how-to-match-unicode-vowels)! (Hint: The concept of a vowel does not even exist in Unicode!) +* Two-pass:
+ Count the negative and positive numbers separately, + then return the maximum. -So first let's put out a clear statement to declare what vowels are. Once and for all, and no matter which case: +Clearly, from an algorithm point of view, and regarding performance, +the single pass alternative is to be preferred. +No waste of resources going through the data twice +only to ignore half of the data in each pass. +So let's write it out: ```perl - my $vowel = qr/[aeiou]/i; +# Single pass solution. +sub maximum_count( @ints ) { + my ( $count_pos, $count_neg ) = ( 0, 0 ); + for ( @ints ) { + if ( $_ > 0 ) { + ++$count_pos + } + elsif ( $_ < 0 ) { + ++$count_neg + } + } + return $count_pos > $count_neg ? $count_pos : $count_neg; +} ``` -Ok. Feels better now. - -The rest is easy! Let's use some readable regular expression to match 'words either starting with a vowel or ending with a vowel': - -```perl - / ^ $vowel | $vowel $ /xi -``` +But even if this probably is high-performance, it has a problem:
+I don't really like it.
+Too much programming! -That's easy, isn't it? +For a two-pass solution, with a little bit of Perl magic and a functional touch, +we can avoid the `for` loop, +and we can avoid using variables at all. -And now we will let `grep` do the counting (it does so in scalar context), and we are done: +For me, this is a much clearer and nicer solution: ```perl use v5.36; -sub word_count( @list ) { - my $vowel = qr/[aeiou]/i; - return scalar grep / ^ $vowel | $vowel $ /xi, @list; +use List::Util qw( max ); + +# Two-pass, preferred solution. +sub maximum_count( @ints ) { + return max( scalar grep( $_ > 0, @ints ), scalar grep( $_ < 0, @ints ) ); } ``` -Makes me happi! +I will reconsider only once I really need that one little bit of higher performance.
+Until then, I am very happy with less programming and less typos! +## Task 2: Sum Difference - -## Task 2: Minimum Common - -> You are given two arrays of integers.
-> Write a script to return the minimum integer common to both arrays. If none found return -1. +> You are given an array of positive integers.
+> Write a script to return the absolute difference between digit sum and element sum of the given array. > > **Example 1** > > ```text -> Input: @array_1 = (1, 2, 3, 4) -> @array_2 = (3, 4, 5, 6) -> Output: 3 +> Input: @ints = (1, 23, 4, 5) +> Output: 18 > -> The common integer in both arrays: 3, 4 -> The minimum is 3. +> Element sum: 1 + 23 + 4 + 5 => 33 +> Digit sum: 1 + 2 + 3 + 4 + 5 => 15 +> Absolute difference: | 33 - 15 | => 18 >``` > >**Example 2** > >```text -> Input: @array_1 = (1, 2, 3) -> @array_2 = (2, 4) -> Output: 2 +> Input: @ints = (1, 2, 3, 4, 5) +> Output: 0 +> +>Element sum: 1 + 2 + 3 + 4 + 5 => 15 +> Digit sum: 1 + 2 + 3 + 4 + 5 => 15 +> Absolute difference: | 15 - 15 | => 0 > ``` > > **Example 3** > > ```text ->Input: @array_1 = (1, 2, 3, 4) -> @array_2 = (5, 6, 7, 8) -> Output: -1 -> ``` - -I first tried to find something like a 'symmetric' solution. Kind of combining the two arrays, and then see if I could derive the result from there. I didn't come up with anything clever. +>Input: @ints = (1, 2, 34) +> Output: 27 +> +> Element sum: 1 + 2 + 34 => 37 +>Digit sum: 1 + 2 + 3 + 4 => 10 +> Absolute difference: | 37 - 10 | => 27 +> ``` -Then, my idea for an 'asymmetric' solution was to walk through one array (that's one side), and check for existence of the element in the other (that's the second side). +We need to compare two sums: -As the number also has to be the smallest possible one, I first sort it numerically. Then we can return `true` for the first element that also exists in the second array. +* the sum of the integers in `@ints`, +* the digit sum of the integers in `@ints`. -Checking for existence is best done with an 'existence hash': +The first part is very simple. Using `sum` from `List::Util`: ```perl - my %is_in_array_2 = map { ( $_ => 1 ) } $array_2->@*; + sum( @ints ) ``` -The sorting and checking fits in one statement, avoiding a `for` loop, when we use `first` from `List::Util`, and then use the 'defined or' operator to return the special value `-1` if we don't find any entry that matches the condition. +For the second part, the digit sum, we have several options: -That can look like this: +* Map each integer in `@ints` into its individual digit sum, + then sum up those digit sums: -```perl -# First solution, using 'sort'. -use v5.36; -use List::Util qw( first ); -sub minimum_common_with_sorting( $array_1, $array_2 ) { - my %is_in_array_2 = map { ( $_ => 1 ) } $array_2->@*; - return - ( first { $is_in_array_2{$_} } - sort { $a <=> $b } $array_1->@* ) - // -1; -} -``` + ```perl + sum( map sum( split "", $_ ), @ints ) + ``` -I implemented this solution first, and it then it kept on thinking about how I could avoid the `sort`, and the multiple passes needed for `sort` and `first`. +* Map each integer in `@ints` into the list of its digits, + then sum up all the digits in one go: -Of course. It's so easy!
-Finding the smallest number in a list of numbers: -That's the reason why the `min` function exists! + ```perl + sum( map split( "", $_ ), @ints ) + ``` -So I flip things around, *first* walking through the first array *without* sorting, -but filtering out only those elements that also exist in the second array. This is the same as finding the *intersection* of the two sets of numbers (notwithstanding repeated elements). + This avoids the repeated calls to `sum` for the individual digit sums. -```perl - grep $is_in_array_2{$_}, $array_1->@* -``` +* Concatenate all the integers in `@ints` into one string, + then split it up into single digits, + and sum them up: -Then find the (hooray!) minimum of those filtered common values: + ```perl + sum( split "", join "", @ints ) + ``` -```perl - min( grep $is_in_array_2{$_}, $array_1->@* ) -``` -Again, if there is no such element, I use the 'defined or' operator to return `-1`. +So here we are again: +There's more than one way to do it...
+And choosing my favorite is not easy here. + +I would probably not use the first one.
+It simply isn't necessary to have every individual element's digit sum. +We can easily avoid all those function calls. + +The second one for me is the 'correct' one.
+Nothing done that is not necessary, very efficient. -Not only that `min` (also from `List::Util`) has a lower time complexity than `sort`, -but the solution also is shorter.
-And I think it is easier to understand, too: +But my heart beats for the third solution. + +Even if it needs that additional step of generating an intermediate string, +I like how concise and simple it is. +And apart from the additional memory needed for that string +I'm not even sure whether it's not just as efficient as the 'correct' second solution.
+Only a benchmark could tell. + +So here we go.
+If in doubt, I choose elegance! ```perl -# My preferred solution. use v5.36; -use List::Util qw( min ); -sub minimum_common( $array_1, $array_2 ) { - my %is_in_array_2 = map { ( $_ => 1 ) } $array_2->@*; - return min( grep $is_in_array_2{$_}, $array_1->@* ) // -1; + +use List::Util qw( sum ); + +sub sum_difference( @ints ) { + return abs( sum( split "", join "", @ints ) - sum( @ints ) ); } ``` -Let's call it 'evolutionari programming'.
-That's OK for me! +**Addendum:** + +I couldn't refrain myself from running that benchmark: + +```text + Rate sum_difference_1 sum_difference_2 sum_difference_3 +sum_difference_1 136455/s -- -12% -24% +sum_difference_2 155121/s 14% -- -14% +sum_difference_3 180004/s 32% 16% -- +``` + +My preferred one-string solution is the fastest!
+What can I say? + #### **Thank you for the challenge!** diff --git a/challenge-320/matthias-muth/blog.txt b/challenge-320/matthias-muth/blog.txt new file mode 100644 index 0000000000..33a2a6220f --- /dev/null +++ b/challenge-320/matthias-muth/blog.txt @@ -0,0 +1 @@ +https://github.com/MatthiasMuth/perlweeklychallenge-club/tree/muthm-320/challenge-320/matthias-muth#readme diff --git a/challenge-320/matthias-muth/perl/ch-1.pl b/challenge-320/matthias-muth/perl/ch-1.pl new file mode 100755 index 0000000000..ae7f2634fd --- /dev/null +++ b/challenge-320/matthias-muth/perl/ch-1.pl @@ -0,0 +1,56 @@ +#!/usr/bin/env perl +# +# The Weekly Challenge - Perl & Raku +# (https://theweeklychallenge.org) +# +# Challenge 320 Task 1: Maximum Count +# +# Perl solution by Matthias Muth. +# + +use v5.36; + +sub maximum_count_1( @ints ) { + my ( $count_pos, $count_neg ) = ( 0, 0 ); + for ( @ints ) { + if ( $_ > 0 ) { + ++$count_pos + } + elsif ( $_ < 0 ) { + ++$count_neg + } + } + return $count_pos > $count_neg ? $count_pos : $count_neg; +} + +use List::Util qw( max ); + +sub maximum_count_2( @ints ) { + return max( scalar grep( $_ > 0, @ints ), scalar grep( $_ < 0, @ints ) ); +} + +*maximum_count = \&maximum_count_2; + +use Test2::V0 qw( -no_srand ); + +is maximum_count( -3, -2, -1, 1, 2, 3 ), 3, + 'Example 1: maximum_count( -3, -2, -1, 1, 2, 3 ) == 3'; +is maximum_count( -2, -1, 0, 0, 1 ), 2, + 'Example 2: maximum_count( -2, -1, 0, 0, 1 ) == 2'; +is maximum_count( 1, 2, 3, 4 ), 4, + 'Example 3: maximum_count( 1, 2, 3, 4 ) == 4'; + +done_testing; + +__END__ + +use Benchmark qw( :all ); + +my @ints = ( -3, -2, -1, 1, 2, 3 ); + +cmpthese -3 => { + maximum_count_1 => sub { maximum_count_1( @ints ) }, + maximum_count_2 => sub { maximum_count_2( @ints ) }, +}; + + diff --git a/challenge-320/matthias-muth/perl/ch-2.pl b/challenge-320/matthias-muth/perl/ch-2.pl new file mode 100755 index 0000000000..eeac1dfa70 --- /dev/null +++ b/challenge-320/matthias-muth/perl/ch-2.pl @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +# +# The Weekly Challenge - Perl & Raku +# (https://theweeklychallenge.org) +# +# Challenge 320 Task 2: Sum Difference +# +# Perl solution by Matthias Muth. +# + +use v5.36; + +use List::Util qw( sum ); + +sub sum_difference_1( @ints ) { + return abs( sum( map sum( split "", $_ ), @ints ) - sum( @ints ) ); +} + +sub sum_difference_2( @ints ) { + return abs( sum( map split( "", $_ ), @ints ) - sum( @ints ) ); +} + +sub sum_difference_3( @ints ) { + return abs( sum( split "", join "", @ints ) - sum( @ints ) ); +} + +*sum_difference = \&sum_difference_3; + +use Test2::V0 qw( -no_srand ); + +is sum_difference( 1, 23, 4, 5 ), 18, + 'Example 1: sum_difference( 1, 23, 4, 5 ) == 18'; +is sum_difference( 1, 2, 3, 4, 5 ), 0, + 'Example 2: sum_difference( 1, 2, 3, 4, 5 ) == 0'; +is sum_difference( 1, 2, 34 ), 27, + 'Example 3: sum_difference( 1, 2, 34 ) == 27'; + +done_testing; + +__END__ + +use Benchmark qw( :all ); + +my @ints = ( 1, 23, 4, 5 ); + +cmpthese -3 => { + sum_difference_1 => sub { sum_difference_1( @ints ) }, + sum_difference_2 => sub { sum_difference_2( @ints ) }, + sum_difference_3 => sub { sum_difference_3( @ints ) }, +}; + + -- cgit From 612f7c4b70ac5ae7c3d78d6eb1edf22a2d900792 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Fri, 9 May 2025 21:28:03 +0100 Subject: - Added solutions by Robbie Hatley. - Added solutions by Luca Ferrari. - Added solutions by Jorg Sommrey. - Added solutions by Thomas Kohler. --- stats/pwc-current.json | 78 ++++++++++++++++++++++++++++++- 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 | 10 ++-- stats/pwc-language-breakdown-summary.json | 8 ++-- stats/pwc-leaders.json | 26 +++++------ stats/pwc-summary-1-30.json | 2 +- stats/pwc-summary-121-150.json | 6 +-- stats/pwc-summary-151-180.json | 6 +-- stats/pwc-summary-181-210.json | 2 +- stats/pwc-summary-211-240.json | 2 +- stats/pwc-summary-241-270.json | 6 +-- stats/pwc-summary-271-300.json | 6 +-- 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 | 18 +++---- stats/pwc-yearly-language-summary.json | 10 ++-- 23 files changed, 138 insertions(+), 62 deletions(-) diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 515a81c596..e9f99c061e 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -110,6 +110,34 @@ "id" : "Jaldhar H. Vyas", "name" : "Jaldhar H. Vyas" }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" + }, { "data" : [ [ @@ -144,6 +172,20 @@ "id" : "Peter Meszaros", "name" : "Peter Meszaros" }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Robbie Hatley", + "name" : "Robbie Hatley" + }, { "data" : [ [ @@ -158,6 +200,20 @@ "id" : "Roger Bell_West", "name" : "Roger Bell_West" }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, { "data" : [ [ @@ -269,6 +325,16 @@ "name" : "Jaldhar H. Vyas", "y" : 5 }, + { + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey", + "y" : 3 + }, + { + "drilldown" : "Luca Ferrari", + "name" : "Luca Ferrari", + "y" : 4 + }, { "drilldown" : "Mark Anderson", "name" : "Mark Anderson", @@ -284,11 +350,21 @@ "name" : "Peter Meszaros", "y" : 2 }, + { + "drilldown" : "Robbie Hatley", + "name" : "Robbie Hatley", + "y" : 3 + }, { "drilldown" : "Roger Bell_West", "name" : "Roger Bell_West", "y" : 4 }, + { + "drilldown" : "Thomas Kohler", + "name" : "Thomas Kohler", + "y" : 4 + }, { "drilldown" : "Ulrich Rieke", "name" : "Ulrich Rieke", @@ -314,7 +390,7 @@ } ], "subtitle" : { - "text" : "[Champions: 17] Last updated at 2025-05-07 14:35:32 GMT" + "text" : "[Champions: 21] Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge - 320" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 6ce23bac43..6c0e1dbdf4 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-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index c56629e463..6f5e72a85f 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-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index 5ed984c52b..3ae7c6b313 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-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 7da987ba95..a393c5aa0d 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-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index 0a5cd066dc..b6f165c394 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-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index f4641d7c7f..09e8594296 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-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index 73bd336711..83a6f1c72a 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,15 +8,15 @@ "data" : [ [ "Perl", - 28 + 34 ], [ "Raku", - 14 + 16 ], [ "Blog", - 4 + 10 ] ], "id" : "320", @@ -349,7 +349,7 @@ { "drilldown" : "320", "name" : "320", - "y" : 46 + "y" : 60 }, { "drilldown" : "319", @@ -441,7 +441,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 3e9e7097dd..5a95ecef9f 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,15 +10,15 @@ "data" : [ [ "Perl", - 16562 + 16568 ], [ "Raku", - 9224 + 9226 ], [ "Blog", - 5847 + 5853 ] ], "dataLabels" : { @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-05-07 14:35:32 GMT" + "text" : "Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index eb24ad541d..992a679f41 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -8,11 +8,11 @@ "data" : [ [ "Raku", - 444 + 446 ], [ "Blog", - 1101 + 1103 ] ], "id" : "Luca Ferrari", @@ -162,11 +162,11 @@ "data" : [ [ "Perl", - 605 + 607 ], [ "Blog", - 84 + 85 ] ], "id" : "Jorg Sommrey", @@ -318,11 +318,11 @@ "data" : [ [ "Perl", - 242 + 244 ], [ "Blog", - 235 + 237 ] ], "id" : "Thomas Kohler", @@ -448,11 +448,11 @@ "data" : [ [ "Perl", - 256 + 258 ], [ "Blog", - 115 + 116 ] ], "id" : "Robbie Hatley", @@ -797,7 +797,7 @@ { "drilldown" : "Luca Ferrari", "name" : "1: Luca Ferrari", - "y" : 3090 + "y" : 3098 }, { "drilldown" : "Roger Bell_West", @@ -842,7 +842,7 @@ { "drilldown" : "Jorg Sommrey", "name" : "10: Jorg Sommrey", - "y" : 1378 + "y" : 1384 }, { "drilldown" : "W. Luis Mochan", @@ -892,7 +892,7 @@ { "drilldown" : "Thomas Kohler", "name" : "20: Thomas Kohler", - "y" : 954 + "y" : 962 }, { "drilldown" : "Feng Chang", @@ -937,7 +937,7 @@ { "drilldown" : "Robbie Hatley", "name" : "29: Robbie Hatley", - "y" : 742 + "y" : 748 }, { "drilldown" : "Mohammad Sajid Anwar", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index 312c906da3..cc73bf4856 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-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 09f6e620cf..a8931b1d00 100644 --- a/stats/pwc-summary-121-150.json +++ b/stats/pwc-summary-121-150.json @@ -29,7 +29,7 @@ 7, 2, 0, - 605, + 607, 8, 2, 23, @@ -99,7 +99,7 @@ 0, 0, 0, - 84, + 85, 0, 0, 1, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 4aaa101664..43113369fa 100644 --- a/stats/pwc-summary-151-180.json +++ b/stats/pwc-summary-151-180.json @@ -60,7 +60,7 @@ 0, 10, 55, - 444, + 446, 14, 4, 0, @@ -95,7 +95,7 @@ 0, 0, 30, - 1101, + 1103, 0, 0, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 4b457bc4f9..c73e7b3b57 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-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 8ba91991b5..96f2669533 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-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 e5484f88d6..5223ad80b7 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -25,7 +25,7 @@ 0, 0, 9, - 256, + 258, 156, 2, 0, @@ -95,7 +95,7 @@ 13, 0, 0, - 115, + 116, 0, 0, 7, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 3c471ea3c8..8f86cf6767 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -35,7 +35,7 @@ 6, 4, 2, - 242, + 244, 1, 10, 14, @@ -105,7 +105,7 @@ 0, 0, 0, - 235, + 237, 0, 3, 0, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 ff476908c7..7bf2148ee7 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -94,7 +94,7 @@ } ], "subtitle" : { - "text" : "[Champions: 23] Last updated at 2025-05-07 14:35:32 GMT" + "text" : "[Champions: 23] Last updated at 2025-05-09 20:27:20 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 530ecdcdb2..3b907ffae8 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-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 a65c414dda..ab4c3f9452 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-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 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 7350cacc86..f119e190ce 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-05-07 14:35:32 GMT" + "text" : "[Champions: 30] Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index 807ceb8b6e..1a8913e920 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -149,7 +149,7 @@ 4, 1, 0, - 311, + 312, 4, 1, 13, @@ -265,7 +265,7 @@ 0, 0, 6, - 131, + 132, 98, 1, 0, @@ -305,7 +305,7 @@ 3, 2, 1, - 123, + 124, 1, 6, 7, @@ -503,7 +503,7 @@ 0, 5, 28, - 222, + 223, 7, 2, 0, @@ -805,7 +805,7 @@ 0, 0, 0, - 81, + 82, 0, 0, 1, @@ -831,7 +831,7 @@ 0, 0, 30, - 221, + 222, 0, 0, 0, @@ -921,7 +921,7 @@ 13, 0, 0, - 115, + 116, 0, 0, 4, @@ -961,7 +961,7 @@ 0, 0, 0, - 120, + 121, 0, 3, 0, @@ -994,7 +994,7 @@ } ], "subtitle" : { - "text" : "[Champions: 323] Last updated at 2025-05-07 14:35:32 GMT" + "text" : "[Champions: 323] Last updated at 2025-05-09 20:27:20 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 47d48cf50b..cb15ef2be6 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -8,15 +8,15 @@ "data" : [ [ "Perl", - 795 + 801 ], [ "Raku", - 358 + 360 ], [ "Blog", - 274 + 280 ] ], "id" : "2025", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 1427 + "y" : 1441 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-07 14:35:32 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-05-09 20:27:20 GMT" }, "title" : { "text" : "The Weekly Challenge Language" -- cgit From f81c10b758026a2c4964f2604c3c13ea38af75ba Mon Sep 17 00:00:00 2001 From: Magnus Markling Date: Sat, 10 May 2025 19:49:00 +0200 Subject: Solve 319 --- challenge-319/memark/uiua/ch-1.ua | 12 ++++++++++++ challenge-319/memark/uiua/ch-2.ua | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 challenge-319/memark/uiua/ch-1.ua create mode 100644 challenge-319/memark/uiua/ch-2.ua diff --git a/challenge-319/memark/uiua/ch-1.ua b/challenge-319/memark/uiua/ch-1.ua new file mode 100644 index 0000000000..55a0e2a8c1 --- /dev/null +++ b/challenge-319/memark/uiua/ch-1.ua @@ -0,0 +1,12 @@ +# https://theweeklychallenge.org/blog/perl-weekly-challenge-319/#TASK1 + +# Uiua 0.16.0-dev.2 +# Experimental! + +WordCount ← /+∨ ∩(≡⌞∊"aoeui") ≡◇⊃⊢⊣ + +┌─╴🧪 + ⍤. =2 WordCount {"unicode" "xml" "raku" "perl"} + ⍤. =2 WordCount {"the" "weekly" "challenge"} + ⍤. =0 WordCount {"perl" "python" "postgres"} +└─╴ diff --git a/challenge-319/memark/uiua/ch-2.ua b/challenge-319/memark/uiua/ch-2.ua new file mode 100644 index 0000000000..d4f365748d --- /dev/null +++ b/challenge-319/memark/uiua/ch-2.ua @@ -0,0 +1,11 @@ +# https://theweeklychallenge.org/blog/perl-weekly-challenge-319/#TASK2 + +# Uiua 0.16.0-dev.2 + +MinimumCommon ← ⨬⋅¯1/↧ ±⊸⧻ ▽⊸∊ + +┌─╴🧪 + ⍤. =3 MinimumCommon [1 2 3 4] [3 4 5 6] + ⍤. =2 MinimumCommon [1 2 3] [2 4] + ⍤. =¯ 1 MinimumCommon [1 2 3 4] [5 6 7 8] +└─╴ -- cgit From ec50e9ceb9af3bf2cd60c8abd7d1694f61a6a47a Mon Sep 17 00:00:00 2001 From: Magnus Markling Date: Sat, 10 May 2025 16:50:00 +0200 Subject: Solve 320 --- challenge-320/memark/uiua/ch-1.ua | 11 +++++++++++ challenge-320/memark/uiua/ch-2.ua | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 challenge-320/memark/uiua/ch-1.ua create mode 100644 challenge-320/memark/uiua/ch-2.ua diff --git a/challenge-320/memark/uiua/ch-1.ua b/challenge-320/memark/uiua/ch-1.ua new file mode 100644 index 0000000000..3627335fd4 --- /dev/null +++ b/challenge-320/memark/uiua/ch-1.ua @@ -0,0 +1,11 @@ +# https://theweeklychallenge.org/blog/perl-weekly-challenge-320/#TASK1 + +# Uiua 0.16.0-dev.2 + +MaximumCount ← ↥∩/+⊃><0 + +┌─╴🧪 + ⍤. =3 MaximumCount [¯3 ¯2 ¯1 1 2 3] + ⍤. =2 MaximumCount [¯2 ¯1 0 0 1] + ⍤. =4 MaximumCount [1 2 3 4] +└─╴ diff --git a/challenge-320/memark/uiua/ch-2.ua b/challenge-320/memark/uiua/ch-2.ua new file mode 100644 index 0000000000..8e8652a3ea --- /dev/null +++ b/challenge-320/memark/uiua/ch-2.ua @@ -0,0 +1,11 @@ +# https://theweeklychallenge.org/blog/perl-weekly-challenge-320/#TASK2 + +# Uiua 0.16.0-dev.2 + +SumDifference ← ⌵-∩/+⊃(∘|≡⋕/$"__") + +┌─╴🧪 + ⍤. =18 SumDifference [1 23 4 5] + ⍤. =0 SumDifference [1 2 3 4 5] + ⍤. =27 SumDifference [1 2 34] +└─╴ -- cgit From 2c6d46fba7dc3e812b7decb8f88265c92b4adb24 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sat, 10 May 2025 16:01:21 -0400 Subject: initial commit --- challenge-320/adam-russell/blog.txt | 1 + challenge-320/adam-russell/perl/ch-1.pl | 23 +++++++++++++++++++++++ challenge-320/adam-russell/perl/ch-2.pl | 27 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 challenge-320/adam-russell/blog.txt create mode 100644 challenge-320/adam-russell/perl/ch-1.pl create mode 100644 challenge-320/adam-russell/perl/ch-2.pl diff --git a/challenge-320/adam-russell/blog.txt b/challenge-320/adam-russell/blog.txt new file mode 100644 index 0000000000..e567a8bf44 --- /dev/null +++ b/challenge-320/adam-russell/blog.txt @@ -0,0 +1 @@ +http://rabbitfarm.com/cgi-bin/blosxom/perl/2025/05/10 diff --git a/challenge-320/adam-russell/perl/ch-1.pl b/challenge-320/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..40e4e23878 --- /dev/null +++ b/challenge-320/adam-russell/perl/ch-1.pl @@ -0,0 +1,23 @@ + + +use v5.40; + + + sub maximum_count{ + my @numbers = @_; + + my $negatives = 0 + grep {$_ < 0} @numbers; + + + my $positives = 0 + grep {$_ > 0} @numbers; + + return (sort {$b <=> $a} ($positives, $negatives))[0]; + } + + +MAIN:{ + say maximum_count -3, -2, -1, 1, 2, 3; + say maximum_count -2, -1, 0, 0, 1; + say maximum_count 1, 2, 3, 4; +} + diff --git a/challenge-320/adam-russell/perl/ch-2.pl b/challenge-320/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..432cee8e70 --- /dev/null +++ b/challenge-320/adam-russell/perl/ch-2.pl @@ -0,0 +1,27 @@ + + +use v5.40; + + + sub sum_difference{ + my @numbers = @_; + + my @digits; + do{ + push @digits, split //, $_; + } for @numbers; + my $digit_sum = unpack(q/%32I*/, pack(q/I*/, @digits)); + + + my $element_sum = unpack(q/%32I*/, pack(q/I*/, @numbers)); + + return abs($digit_sum - $element_sum); + } + + +MAIN:{ + say sum_difference 1, 23, 4, 5; + say sum_difference 1, 2, 3, 4, 5; + say sum_difference 1, 2, 34; +} + -- cgit From 96ffdd8c13c12259b278e66fb1e2572a9688b69b Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Sun, 11 May 2025 00:38:54 +0100 Subject: - Added