TABLE OF CONTENTS
1. HEADLINES
2. SPONSOR
3. RECAP
4. PERL REVIEW
5. RAKU REVIEW
6. CHART
7. NEW MEMBERS
8. GUESTS
9. TASK #1: Hamiltonian Cycle
10. TASK #2: Replace Question Mark
HEADLINES
Welcome to the Week #382 of The Weekly Challenge.
I am very excited to announce that my first book, Design Patterns in Modern Perl, is now available in paperback version on Amazon. Some of the team members shared the photo of the book they received. I request those who purchased the book, please share your review on Amazon. It will help others to buy my book.
Thanks to Amazon, I received 5 copies of paperback version of the book. It feels great to hold my first book in my hand. My kids, specially the twins (9 years), were very happy to see my face on the back cover. I mentioned them by name in the dedication section. I saw big smile on their face when they found out.
I have received so many messages on social media when I shared the news. I am grateful to each and everyone for the kind message. I already started working on my second book (Dec, 2025). I am hoping to get it ready to launch at London Perl Workshop 2026. The same way, how I launched my first book at LPW 2025. The book is all about DBIx::Class.
Below is my contributions to the Task #1 of Week #381.
Perl: source code
sub valid_square {
my ($matrix) = @_;
my $n = scalar @$matrix;
for my $row (@$matrix) {
my %seen = map { $_ => 1 } @$row;
return 0 unless scalar keys %seen == $n && all { $_ >= 1 && $_ <= $n } keys %seen;
}
for my $col_idx (0 .. $n - 1) {
my %seen;
for my $row_idx (0 .. $n - 1) {
$seen{$matrix->[$row_idx][$col_idx]} = 1;
}
return 0 unless scalar keys %seen == $n && all { $_ >= 1 && $_ <= $n } keys %seen;
}
return 1;
}
Raku: source code
sub valid-square($matrix) {
my $n = $matrix.elems;
for @$matrix -> $row {
my %seen = $row.Set;
return 0 unless %seen.elems == $n && %seen.keys.all ~~ 1..$n;
}
for 0 .. $n - 1 -> $col_idx {
my %seen;
for 0 .. $n - 1 -> $row_idx {
%seen{$matrix[$row_idx][$col_idx]} = 1;
}
return 0 unless %seen.elems == $n && %seen.keys.all ~~ 1..$n;
}
return 1;
}
Python: source code
def valid_square(matrix):
n = len(matrix)
for row in matrix:
seen = set(row)
if len(seen) != n or not all(1 <= x <= n for x in seen):
return 0
for col_idx in range(n):
seen = set()
for row_idx in range(n):
seen.add(matrix[row_idx][col_idx])
if len(seen) != n or not all(1 <= x <= n for x in seen):
return 0
return 1
Thank you Team PWC, once again.
Happy Hacking!!
Last 5 weeks mainstream contribution stats. Thank you Team PWC for your support and encouragements.
Week |
Perl |
Raku |
Blog |
377 |
45 | 23 | 13 |
378 |
50 | 28 | 14 |
379 |
45 | 25 | 13 |
380 |
48 | 23 | 13 |
381 |
43 | 23 | 13 |
Last 5 weeks guest contribution stats. Thank you each and every guest contributors for your time and efforts.
Week |
Guests |
Contributions |
Languages |
377 |
13 | 67 | 23 |
378 |
17 | 89 | 31 |
379 |
17 | 80 | 27 |
380 |
18 | 93 | 29 |
381 |
16 | 78 | 26 |
TOP 10 Guest Languages
Do you see your favourite language in the Top #10? If not then why not contribute regularly and make it to the top.
1. Python (4503)
2. Rust (1192)
3. C (1053)
4. Haskell (932)
5. Ruby (932)
6. Lua (916)
7. C++ (737)
8. Go (721)
9. JavaScript (646)
10. Java (532)
Blogs with Creative Title
1. Same Element by Arne Sommer.
2. All The Same by Jorg Sommrey.
3. Smaller? Greater? Same! by Matthias Muth.
4. Oh, yes! I’m the great row column! by Packy Anderson.
5. Same, smaller, greater by Peter Campbell Smith.
6. Same Element, Different Column by Roger Bell_West.
7. Grep, set and match by Simon Green.
GitHub Repository Stats
1. Commits: 50,510 (+96)
2. Pull Requests: 14,401 (+23)
3. Contributors: 281
4. Fork: 353
5. Stars: 217 (+2)
SPONSOR
With start of Week #355, we have a new sponsor Marc Perry until the end of year 2026. Having said we are looking for more sponsors so that we can go back to weekly winner. If anyone interested please get in touch with us at perlweeklychallenge@yahoo.com. Thanks for your support in advance. You can find more informations here.
RECAP
Quick recap of The Weekly Challenge - 381 by Mohammad Sajid Anwar.
PERL REVIEW
If you missed any past reviews then please check out the collection.
RAKU REVIEW
If you missed any past reviews then please check out the collection.
CHART
Please take a look at the charts showing interesting data.
I would like to THANK every member of the team for their valuable suggestions. Please do share your experience with us.
NEW MEMBERS
Please find out How to contribute?, if you have any doubts.
Please try the excellent tool EZPWC created by respected member Saif Ahmed of Team PWC.
GUESTS
ygrek, an experienced K hacker joined the Team PWC.
Please check out the guest contributions for the Week #381.
Please find past solutions by respected guests. Please share your creative solutions in other languages.
Task 1: Hamiltonian Cycle
Submitted by: Peter Campbell Smith
You are given a target number.
Write a script to arrange all the whole numbers from 1 up to the given target number into a circle so that every pair of side-by-side numbers adds up to a perfect square. Please make sure, the last number and the first must also add up to a square.
Example 1
Input: $n = 32
Output: 1, 8, 28, 21, 4, 32, 17, 19, 30, 6, 3, 13, 12, 24, 25, 11, 5, 31, 18, 7, 29, 20, 16, 9, 27, 22, 14, 2, 23, 26, 10, 15
1 + 8 = 9
8 + 28 = 36
28 + 21 = 49
21 + 4 = 25
4 + 32 = 36
32 + 17 = 49
17 + 19 = 36
19 + 30 = 49
so on, all the way through the sequence.
Example 2
Input: $n = 15
Output: ()
No valid circular list of numbers exists.
Example 3
Input: $n = 34
Output: 1, 8, 17, 32, 4, 21, 28, 11, 25, 24, 12, 13, 3, 6, 30, 19, 14, 22, 27, 9, 16, 20, 29, 7, 18, 31, 5, 4, 34, 15, 10, 26, 23, 2
Task 2: Replace Question Mark
Submitted by: Simon Green
You are given a string that contains only 0, 1 and ? characters.
Write a script to generate all possible combinations when replacing the question marks with a zero or one.
Example 1
Input: $str = "01??0"
Output: ("01000", "01010", "01100", "01110")
Example 2
Input: $str = "101"
Output: ("101")
Example 3
Input: $str = "???"
Output: ("000", "001", "010", "011", "100", "101", "110", "111")
Example 4
Input: $str = "1?10"
Output: ("1010", "1110")
Example 5
Input: $str = "1?1?0"
Output: ("10100", "10110", "11100", "11110")
By submitting a response to the challenge you agree that your name or pseudonym, any photograph you supply and any other personal information contained in your submission may be published on this website and the associated mobile app. Last date to submit the solution 23:59 (UK Time) Sunday 19th July 2026.