The Weekly Challenge - 342

Monday, Oct 6, 2025| Tags: Perl, Raku

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: Balance String

10. TASK #2: Max Score


HEADLINES


Welcome to the Week #342 of The Weekly Challenge.

Today is the first Monday of the month and it’s time to declare the next Champion of The Weekly Challenge. It’s with high regard and respect, I announce David Ferrone as the new champion. Congratulations, David.

For those new to the team, David was last declared champion in March 2023. He is currently ranked #35 with a total score of 684. As of today, he has contributed 320 Perl solutions, 13 Raku solutions and 9 blog posts.

Week #341 became very special for several reasons. First, it was the best week of 2025 for guest contributions. We also nearly beat the best week of the year for regular contributions, missing the record by a very small margin. The record is held Week #333 with 106 contributions; in Week #341, we received 104. With some late contributions, Week #341 might still take the top spot. Nevertheless, I am very happy with all the support and encouragement.

Another reason Week #341 was special is the return of Ryan Thompson after a long break with contributions in Perl and a bonus creative and entertaining blog post.

Speaking of comebacks, we also welcomed back Luca Ferrari after a short back. Apparently he has been enjoying a vacation in Japan. I hope he had great time. He has returned with his powerful contributions across multiple streams.

One more welcome is in order for Vinod Kumar K, who is back with contributions in Perl and Python.

On a different note, I must point out that the Broken Keyboard task from Week #341 is a repeat. It was originally used in Week #275. I take full responsibility for this. I should have been more carefull. Unfortunately, this is not the first time, it has happened. It was reported by Packy Anderson but by then it was too late to change it.

Finally, it’s time to share my own contributions in Perl and Python. For now, I’m sticking to just one task so I can maintain my momentum.

Perl


#!/usr/bin/env perl

use v5.38;
use Test::More;

sub typable_word_count($str, $keys) {
    my @words = split /\s+/, $str;
    return scalar @words unless @$keys;

    my $broken_chars = quotemeta(join '', @$keys);
    return scalar grep { !/[$broken_chars]/i } @words;
}

my $examples = [
    { str => 'Hello World',          keys => ['d'],      exp => 1 },
    { str => 'apple banana cherry',  keys => ['a', 'e'], exp => 0 },
    { str => 'Coding is fun',        keys => [],         exp => 3 },
    { str => 'The Weekly Challenge', keys => ['a','b'],  exp => 2 },
    { str => 'Perl and Python',      keys => ['p'],      exp => 1 },
];

is(typable_word_count($_->{str}, $_->{keys}), $_->{exp}) for @$examples;

done_testing;

Python


#!/usr/bin/env python3

def typable_word_count(text: str, broken_keys: list[str]) -> int:
    words = text.split()
    if not broken_keys:
        return len(words)

    broken_chars  = set(key.lower() for key in broken_keys)
    typable_count = sum(
        1 for word in words
        if all(char.lower() not in broken_chars for char in word)
    )

    return typable_count

examples = [
    ('Hello World',          ['d'],      1),
    ('apple banana cherry',  ['a', 'e'], 0),
    ('Coding is fun',        [],         3),
    ('The Weekly Challenge', ['a', 'b'], 2),
    ('Perl and Python',      ['p'],      1),
]

for text, keys, expected in examples:
    result = typable_word_count(text, keys)
    assert result == expected, (
        f"Assertion Failed: Input: '{text}', Keys: {keys} | "
        f"Expected: {expected}, Got: {result}"
    )

print("\nAll tests passed successfully.")

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   
   337       48       20       14   
   338       45       23       14   
   339       45       23       14   
   340       49       25       12   
   341       55       25       24   

Last 5 weeks guest contribution stats. Thank you each and every guest contributors for your time and efforts.

  Week      Guests       Contributions       Languages   
   337       13       54       19   
   338       13       58       19   
   339       13       64       21   
   340       13       55       17   
   341       15       67       19   

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     (3639)
 2. Rust       (1012)
 3. Ruby       (834)
 4. Haskell    (819)
 5. Lua        (773)
 6. C++        (655)
 7. C          (596)
 8. JavaScript (592)
 9. Go         (553)
10. BQN        (472)

Blogs with Creative Title


1. Reverse Broken Again by Arne Sommer.

2. back from Japan by Luca Ferrari.

3. (Pre-)Fix what is Broken by Matthias Muth.

4. Something just BROKE… by Packy Anderson.

5. Broken keys and mixed up words by Peter Campbell Smith.

6. Broken Prefix by Roger Bell_West.

7. Reversing my broken keys by Simon Green.


GitHub Repository Stats


1. Commits: 45,597 (+133)

2. Pull Requests: 12,754 (+49)

3. Contributors: 264

4. Fork: 337 (+1)

5. Stars: 197 (+1)



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 - 341 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 #341.

Please find past solutions by respected guests. Please share your creative solutions in other languages.


Task 1: Balance String

Submitted by: Mohammad Sajid Anwar

You are given a string made up of lowercase English letters and digits only.

Write a script to format the give string where no letter is followed by another letter and no digit is followed by another digit. If there are multiple valid rearrangements, always return the lexicographically smallest one. Return empty string if it is impossible to format the string.


Example 1

Input: $str = "a0b1c2"
Output: "0a1b2c"

Example 2

Input: $str = "abc12"
Output: "a1b2c"

Example 3

Input: $str = "0a2b1c3"
Output: "0a1b2c3"

Example 4

Input: $str = "1a23"
Output: ""

Example 5

Input: $str = "ab123"
Output: "1a2b3"

Task 2: Max Score

Submitted by: Mohammad Sajid Anwar

You are given a string, $str, containing 0 and 1 only.

Write a script to return the max score after splitting the string into two non-empty substrings. The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.


Example 1

Input: $str = "0011"
Output: 4

1: left = "0", right = "011" => 1 + 2 => 3
2: left = "00", right = "11" => 2 + 2 => 4
3: left = "001", right = "1" => 2 + 1 => 3

Example 2

Input: $str = "0000"
Output: 3

1: left = "0", right = "000" => 1 + 0 => 1
2: left = "00", right = "00" => 2 + 0 => 2
3: left = "000", right = "0" => 3 + 0 => 3

Example 3

Input: $str = "1111"
Output: 3

1: left = "1", right = "111" => 0 + 3 => 3
2: left = "11", right = "11" => 0 + 2 => 2
3: left = "111", right = "1" => 0 + 1 => 1

Example 4

Input: $str = "0101"
Output: 3

1: left = "0", right = "101" => 1 + 2 => 3
2: left = "01", right = "01" => 1 + 1 => 2
3: left = "010", right = "1" => 2 + 1 => 3

Example 5

Input: $str = "011101"
Output: 5

1: left = "0", right = "11101" => 1 + 4 => 5
2: left = "01", right = "1101" => 1 + 3 => 4
3: left = "011", right = "101" => 1 + 2 => 3
4: left = "0111", right = "01" => 1 + 1 => 2
5: left = "01110", right = "1" => 2 + 1 => 3


Last date to submit the solution 23:59 (UK Time) Sunday 12th October 2025.


SO WHAT DO YOU THINK ?

If you have any suggestions or ideas then please do share with us.

Contact with me