The Weekly Challenge - 341

Monday, Sep 29, 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: Broken Keyboard

10. TASK #2: Reverse Prefix


HEADLINES


Welcome to the Week #341 of The Weekly Challenge.

I noticed Packy Anderson and Ali Moradi forgot to submit the contributions. I manually pulled it somehow and merged it. I hope, this is acceptable.

Second week in a row, I found time to contribute. However this time, I even shared solution in Python too as well as Perl.

Perl


#!/usr/bin/env perl

use v5.38;
use Test::More;

my $examples = {
    1 => { str => 'abbaca',   exp => 'ca' },
    2 => { str => 'azxxzy',   exp => 'ay' },
    3 => { str => 'aaaaaaaa', exp => ''   },
    4 => { str => 'aabccba',  exp => 'a'  },
    5 => { str => 'abcddcba', exp => ''   },
};

foreach my $id (keys %$examples) {
    is(remove_duplicates($examples->{$id}->{str}), $examples->{$id}->{exp})
}

done_testing;

sub remove_duplicates($str) {
    return $str if length($str) < 2;

    for (my $i = 0; $i < length($str) - 1; $i++) {
        if (substr($str, $i, 1) eq substr($str, $i + 1, 1)) {
            my $new_str = substr($str, 0, $i) . substr($str, $i + 2);
            return remove_duplicates($new_str);
        }
    }

    return $str;
}

Python


#!/usr/bin/env python3

import unittest

def remove_duplicates(s: str) -> str:
    if len(s) < 2:
        return s

    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            new_str = s[:i] + s[i + 2:]
            return remove_duplicates(new_str)

    return s

class TestRemoveDuplicates(unittest.TestCase):
    def test_examples(self):
        examples = {
            1: {'str': 'abbaca',   'exp': 'ca'},
            2: {'str': 'azxxzy',   'exp': 'ay'},
            3: {'str': 'aaaaaaaa', 'exp': ''},
            4: {'str': 'aabccba',  'exp': 'a'},
            5: {'str': 'abcddcba', 'exp': ''},
        }

        for example_id, example_data in examples.items():
            with self.subTest(example_id=example_id, example_str=example_data['str']):
                result = remove_duplicates(example_data['str'])
                self.assertEqual(result, example_data['exp'])

if __name__ == '__main__':
    unittest.main()

Happy Hacking!!


Last 5 weeks mainstream contribution stats. Thank you Team PWC for your support and encouragements.

  Week      Perl       Raku       Blog   
   336       46       24       13   
   337       48       20       14   
   338       45       23       14   
   339       45       23       14   
   340       49       25       12   

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

  Week      Guests       Contributions       Languages   
   336       13       54       18   
   337       13       54       19   
   338       13       58       19   
   339       13       64       21   
   340       13       55       17   

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     (3620)
 2. Rust       (1008)
 3. Ruby       (830)
 4. Haskell    (817)
 5. Lua        (771)
 6. C++        (653)
 7. C          (596)
 8. JavaScript (590)
 9. Go         (547)
10. BQN        (470)

Blogs with Creative Title


1. Ascending Duplicates by Arne Sommer.

2. Two Times Two Lines by Matthias Muth.

3. Rising in Num by Packy Anderson.

4. Deduplicate and going up by Peter Campbell Smith.

5. Ascending Duplicates by Roger Bell_West.

6. Ascending Regex to remove the Duplicates by Simon Green.


GitHub Repository Stats


1. Commits: 45,464 (+98)

2. Pull Requests: 12,705 (+37)

3. Contributors: 264

4. Fork: 336

5. Stars: 196



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

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


Task 1: Broken Keyboard

Submitted by: Mohammad Sajid Anwar

You are given a string containing English letters only and also you are given broken keys.

Write a script to return the total words in the given sentence can be typed completely.


Example 1

Input: $str = 'Hello World', @keys = ('d')
Output: 1

With broken key 'd', we can only type the word 'Hello'.

Example 2

Input: $str = 'apple banana cherry', @keys = ('a', 'e')
Output: 0

Example 3

Input: $str = 'Coding is fun', @keys = ()
Output: 3

No keys broken.

Example 4

Input: $str = 'The Weekly Challenge', @keys = ('a','b')
Output: 2

Example 5

Input: $str = 'Perl and Python', @keys = ('p')
Output: 1

Task 2: Reverse Prefix

Submitted by: Mohammad Sajid Anwar

You are given a string, $str and a character in the given string, $char.

Write a script to reverse the prefix upto the first occurrence of the given $char in the given string $str and return the new string.


Example 1

Input: $str = "programming", $char = "g"
Output: "gorpramming"

Reverse of prefix "prog" is "gorp".

Example 2

Input: $str = "hello", $char = "h"
Output: "hello"

Example 3

Input: $str = "abcdefghij", $char = "h"
Output: "hgfedcbaij"

Example 4

Input: $str = "reverse", $char = "s"
Output: "srevere"

Example 5

Input: $str = "perl", $char = "r"
Output: "repl"


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


SO WHAT DO YOU THINK ?

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

Contact with me