Perl Weekly Challenge 373.
My solutions (task 1 and task 2 ) to the The Weekly Challenge - 373.
Task 1: Equal List
Submitted by: Mohammad Sajid Anwar
You are given two arrays of strings.
Write a script to return true if the two given array
represent the same strings otherwise false.
Example 1
Input: @arr1 = ("a", "bc")
@arr2 = ("ab", "c")
Output: true
Array 1: "a" + "bc" = "abc"
Array 2: "ab" + "c" = "abc"
Example 2
Input: @arr1 = ("a", "b", "c")
@arr2 = ("a", "bc")
Output: true
Array 1: "a" + "b" + "c" = "abc"
Array 2: "a" + "bc" = "abc"
Example 3
Input: @arr1 = ("a", "bc")
@arr2 = ("a", "c", "b")
Output: false
Array 1: "a" + "bc" = "abc"
Array 2: "a" + "c" + "b" = "acb"
Example 4
Input: @arr1 = ("ab", "c", "")
@arr2 = ("", "a", "bc")
Output: true
Array 1: "ab" + "c" + "" = "abc"
Array 2: "" + "a" + "bc" = "abc"
Example 5
Input: @arr1 = ("p", "e", "r", "l")
@arr2 = ("perl")
Output: true
Array 1: "p" + "e" + "r" + "l" = "perl"
Array 2: "perl"

Well, this seems very simple. Join both sets of strings into two strings and compare them. The result takes a one-liner.
Examples:
perl -E '
for my($x,$y)(@ARGV){say"$x; $y -> ",f($x)eq f($y)?"T":"F";}sub f($x){join"",split/\s*,\s*/,$x}
' "a, bc" "ab, c" "a, b, c" "a, bc" "a, bc" "a, c, b" "ab, c, " ", a, bc" "p, e, r, l" "perl"
Results:
a, bc; ab, c -> T
a, b, c; a, bc -> T
a, bc; a, c, b -> F
ab, c, ; , a, bc -> T
p, e, r, l; perl -> T
The full code is:
1 # Perl weekly challenge 373
2 # Task 1: Equal List
3 #
4 # See https://wlmb.github.io/2026/05/11/PWC373/#task-1-equal-list
5 use v5.36;
6 die <<~"FIN" unless @ARGV and @ARGV%2==0;
7 Usage: $0 S0a S0b S1a S1b ...
8 to compare the set of comma separated strings Sna with Snb.
9 FIN
10
11 for my($x,$y)(@ARGV){
12 say "$x; $y -> ", join_split($x) eq join_split($y)? "True":"False";
13 }
14
15 sub join_split($x){
16 join "", split /\s*,\s*/, $x
17 }
18
Example:
./ch-1.pl "a, bc" "ab, c" \
"a, b, c" "a, bc" \
"a, bc" "a, c, b" \
"ab, c, " ", a, bc" \
"p, e, r, l" "perl"
Results:
a, bc; ab, c -> True
a, b, c; a, bc -> True
a, bc; a, c, b -> False
ab, c, ; , a, bc -> True
p, e, r, l; perl -> True
Task 2: List Division
Submitted by: Mark Anderson
You are given a list and a non-negative integer.
Write a script to divide the given list into given
non-negative integer equal parts. Return -1 if the integer
is more than the size of the list.
Example 1
Input: @list = (1,2,3,4,5), $n = 2
Output: ((1,2,3), (4,5))
5 / 2 = 2 remainder 1.
The extra element goes into the first chunk.
Example 2
Input: @list = (1,2,3,4,5,6), $n = 3
Output: ((1,2), (3,4), (5,6))
6 / 3 = 2 remainder 0.
Example 3
Input: @list = (1,2,3), $n = 2
Output: ((1,2), (3))
Example 4
Input: @list = (1,2,3,4,5,6,7,8,9,10), $n = 5
Output: ((1,2), (3,4), (5,6), (7,8), (9,10))
Example 5
Input: @list = (1,2,3), $n = 4
Output: -1
Example 6
Input: @list = (72,57,89,55,36,84,10,95,99,35), $n = 7;
Output: ((72,57), (89,55), (36,84), (10), (95), (99), (35))
I assume the input is a space separated list followed by the
integer. I split the list, take its size, divide it by the
integer and get the remainder. I repeatedly splice the list
joining the first $n elements, and adding one of the
remaining terms until they are exhausted. The code takes a
two-liner.
Examples:
perl -E '
for my($l,$n)(@ARGV){$s=(@l=split" ",$l)/$n; $r=@l%$n;say "$l, $n -> ",
$n>@l?-1:map{"(".join(" ",splice(@l,0,$s+($_<=$r))).")"}(1..$n)}
' "1 2 3 4 5" 2 "1 2 3 4 5 6" 3 "1 2 3" 2 "1 2 3 4 5 6 7 8 9 10" 5 \
"1 2 3" 4 "72 57 89 55 36 84 10 95 99 35" 7
Results:
1 2 3 4 5, 2 -> (1 2 3)(4 5)
1 2 3 4 5 6, 3 -> (1 2)(3 4)(5 6)
1 2 3, 2 -> (1 2)(3)
1 2 3 4 5 6 7 8 9 10, 5 -> (1 2)(3 4)(5 6)(7 8)(9 10)
1 2 3, 4 -> -1
72 57 89 55 36 84 10 95 99 35, 7 -> (72 57)(89 55)(36 84)(10)(95)(99)(35)
The full code is:
1 # Perl weekly challenge 373
2 # Task 2: List Division
3 #
4 # See https://wlmb.github.io/2026/05/11/PWC373/#task-2-list-division
5 use v5.36;
6 use feature qw(try);
7 die <<~"FIN" unless @ARGV and @ARGV%2==0;
8 Usage: $0 L0 N0 L1 N1...
9 to split the space separated list Ln into Nn (almost) equal parts.
10 FIN
11 for my ($list, $pieces)(@ARGV){
12 try {
13 die "Number of pieces must be >= 1: $pieces" unless $pieces >= 1;
14 my @list = split " ", $list;
15 my $size = @list / $pieces;
16 my $remainder = @list % $pieces;
17 my @result = $pieces > @list
18 ? -1
19 : map{
20 "("
21 . join(" ", splice(@list, 0, $size + ($_<=$remainder)))
22 .")"
23 } (1 .. $pieces);
24 say "$list, $pieces -> @result";
25 }
26 catch($e){ warn $e }
27 }
Example:
./ch-2.pl "1 2 3 4 5" 2 "1 2 3 4 5 6" 3 "1 2 3" 2 "1 2 3 4 5 6 7 8 9 10" 5 \
"1 2 3" 4 "72 57 89 55 36 84 10 95 99 35" 7
Results:
1 2 3 4 5, 2 -> (1 2 3) (4 5)
1 2 3 4 5 6, 3 -> (1 2) (3 4) (5 6)
1 2 3, 2 -> (1 2) (3)
1 2 3 4 5 6 7 8 9 10, 5 -> (1 2) (3 4) (5 6) (7 8) (9 10)
1 2 3, 4 -> -1
72 57 89 55 36 84 10 95 99 35, 7 -> (72 57) (89 55) (36 84) (10) (95) (99) (35)
/;
Written on May 11, 2026