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: Peak Positions
10. TASK #2: Last Visitor
HEADLINES
Welcome to the Week #345 of The Weekly Challenge.
I just noticed, we now have guest contributions in 117 different programming languages and Python being the #1 in the list.
Also the Centurion Club is growing very fast, as of today, we have 86 members in the club.
Another week another contributions from my side. It feels nice to be able to take part in the weekly challenge. The motivation comes from the active team members, specially the ones active on Facebook.
First time weekly challenge blogger, Vinod Kumar K, shared his first blog post. Congratulation and thank you.
Perl
#!/usr/bin/env perl
use Test::More;
use Test::Deep;
my @examples = (
{ input => { arr => [1, 2, 3, 4], x => 12 }, exp => [1, 2, 4, 6] },
{ input => { arr => [2, 7, 4], x => 181 }, exp => [4, 5, 5] },
{ input => { arr => [9, 9, 9], x => 1 }, exp => [1, 0, 0, 0] },
{ input => { arr => [1, 0, 0, 0, 0], x => 9999 }, exp => [1, 9, 9, 9, 9] },
{ input => { arr => [0], x => 1000 }, exp => [1, 0, 0, 0] },
);
foreach my $example (@examples) {
is_deeply([add_to_array_form($example->{input}{arr}, $example->{input}{x})],
$example->{exp});
}
done_testing;
sub add_to_array_form { map $_+0, split //, join('', @{$_[0]}) + $_[1] }
Raku
#!/usr/bin/env raku
use Test;
my @examples = (
{ input => { arr => [1, 2, 3, 4], x => 12 }, exp => [1, 2, 4, 6] },
{ input => { arr => [2, 7, 4], x => 181 }, exp => [4, 5, 5] },
{ input => { arr => [9, 9, 9], x => 1 }, exp => [1, 0, 0, 0] },
{ input => { arr => [1, 0, 0, 0, 0], x => 9999 }, exp => [1, 9, 9, 9, 9] },
{ input => { arr => [0], x => 1000 }, exp => [1, 0, 0, 0] },
);
for @examples -> $example {
is-deeply([add-to-array-form($example<input><arr>, $example<input><x>)],
$example<exp>);
}
done-testing;
sub add-to-array-form($arr, $x) { ($arr.join('') + $x).comb».Int }
Python
#!/usr/bin/env python3
def add_to_array_form(arr, x):
return [int(d) for d in str(int(''.join(map(str, arr))) + x)]
if __name__ == "__main__":
examples = [
{"input": {"arr": [1, 2, 3, 4], "x": 12}, "exp": [1, 2, 4, 6]},
{"input": {"arr": [2, 7, 4], "x": 181}, "exp": [4, 5, 5]},
{"input": {"arr": [9, 9, 9], "x": 1}, "exp": [1, 0, 0, 0]},
{"input": {"arr": [1, 0, 0, 0, 0], "x": 9999}, "exp": [1, 9, 9, 9, 9]},
{"input": {"arr": [0], "x": 1000}, "exp": [1, 0, 0, 0]},
]
for example in examples:
result = add_to_array_form(example["input"]["arr"], example["input"]["x"])
assert result == example["exp"], f"Expected {example['exp']}, got {result}"
print("All tests passed!")
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 |
340 |
51 | 25 | 13 |
341 |
57 | 25 | 25 |
342 |
51 | 22 | 15 |
343 |
44 | 19 | 13 |
344 |
45 | 25 | 17 |
Last 5 weeks guest contribution stats. Thank you each and every guest contributors for your time and efforts.
Week |
Guests |
Contributions |
Languages |
340 |
13 | 55 | 17 |
341 |
15 | 67 | 19 |
342 |
14 | 46 | 14 |
343 |
15 | 61 | 20 |
344 |
16 | 60 | 18 |
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 (3690)
2. Rust (1026)
3. Ruby (840)
4. Haskell (825)
5. Lua (783)
6. C++ (661)
7. C (596)
8. JavaScript (594)
9. Go (565)
10. BQN (478)
Blogs with Creative Title
1. Form Formation by Arne Sommer.
2. Pick Up the Pieces by Bob Lied.
3. Turning Arrays Into Arrays by Jorg Sommrey.
4. Lazyness and too much tasks! by Luca Ferrari.
5. Take it to the Limits by Matthias Muth.
6. A-ray Sunshine! by Packy Anderson.
7. Hip, hip, array! by Peter Campbell Smith.
8. All is Array Formation by Roger Bell_West.
9. The one about arrays by Simon Green.
GitHub Repository Stats
1. Commits: 45,959 (+133)
2. Pull Requests: 12,883 (+50)
3. Contributors: 264
4. Fork: 337
5. Stars: 198
SPONSOR
With start of Week #268, we have a new sponsor Lance Wicks until the end of year 2025. 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.
RECAP
Quick recap of The Weekly Challenge - 344 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
Please check out the guest contributions for the Week #344.
Please find past solutions by respected guests. Please share your creative solutions in other languages.
Task 1: Peak Positions
Submitted by: Mohammad Sajid Anwar
You are given an array of integers, @ints.
Find all the peaks in the array, a peak is an element that is strictly greater than its left and right neighbours. Return the indices of all such peak positions.
Example 1
Input: @ints = (1, 3, 2)
Output: (1)
Example 2
Input: @ints = (2, 4, 6, 5, 3)
Output: (2)
Example 3
Input: @ints = (1, 2, 3, 2, 4, 1)
Output: (2, 4)
Example 4
Input: @ints = (5, 3, 1)
Output: (0)
Example 5
Input: @ints = (1, 5, 1, 5, 1, 5, 1)
Output: (1, 3, 5)
Task 2: Last Visitor
Submitted by: Mohammad Sajid Anwar
You are given an integer array @ints where each element is either a positive integer or -1.
We process the array from left to right while maintaining two lists:
@seen: stores previously seen positive integers (newest at the front)
@ans: stores the answers for each -1
Rules:
If $ints[i] is a positive number -> insert it at the front of @seen
If $ints[i] is -1:
Let $x be how many -1s in a row we’ve seen before this one.
If $x < len(@seen) -> append seen[x] to @ans
Else -> append -1 to @ans
At the end, return @ans.
Example 1
Input: @ints = (5, -1, -1)
Output: (5, -1)
@seen = (5)
First -1: @ans = (5)
Second -1: @ans = (5, -1)
Example 2
Input: @ints = (3, 7, -1, -1, -1)
Output: (7, 3, -1)
@seen = (3, 7)
First -1: @ans = (7)
Second -1: @ans = (7, 3)
Third -1: @ans = (7, 3, -1)
Example 3
Input: @ints = (2, -1, 4, -1, -1)
Output: (2, 4, 2)
Example 4
Input: @ints = (10, 20, -1, 30, -1, -1)
Output: (20, 30, 20)
Example 5
Input: @ints = (-1, -1, 5, -1)
Output: (-1, -1, 5)
Last date to submit the solution 23:59 (UK Time) Sunday 2nd November 2025.