The Weekly Challenge: 373

5 min read
← Back to Challenges

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: Equal List

10. TASK #2: List Division

HEADLINES


Welcome to the Week #373 of The Weekly Challenge.

I would like to thank Early Bird Club members for helping me review the weekly challenge. Without your support, I wouldn’t have come this far. I would also like to thank each and everyone who suggested fun challenges.

Welcome back, HVukman, after a short break and thanks for your contributions in Lua.

Thank you, Bob Lied, for sharing solutions to the past challenges.

Thank you, Lubos Kolouch, for sharing blog post to the past challenges.

With so much happening, the overall stats now looking much better. I will share more on that next week.

Sorry for the delay in this week challenge.

Below is my contributions to the Task #1 of Week #372.

Perl: source code


sub rearrange_spaces {
    my ($text) = @_;

    my $total_spaces = ($text =~ tr/ //);
    my @words        = split(' ', $text);
    my $word_count   = scalar @words;

    if ($word_count == 1) {
        return $words[0] . (" " x $total_spaces);
    }

    my $gap_count      = $word_count - 1;
    my $spaces_per_gap = int($total_spaces / $gap_count);
    my $remainder      = $total_spaces % $gap_count;
    my $gap_string     = " " x $spaces_per_gap;
    my $result         = join($gap_string, @words);
    $result .= (" " x $remainder);

    return $result;
}

Raku: source code


sub rearrange-spaces($text) {
    my $total-spaces = $text.comb(' ').elems;
    my @words        = $text.words;
    my $word-count   = @words.elems;

    if $word-count == 1 {
        return @words[0] ~ (" " x $total-spaces);
    }

    my $gap-count      = $word-count - 1;
    my $spaces-per-gap = $total-spaces div $gap-count;
    my $remainder      = $total-spaces % $gap-count;
    my $gap-string     = " " x $spaces-per-gap;
    my $result         = @words.join($gap-string);
    $result ~= (" " x $remainder);

    return $result;
}

Python: source code


def rearrange_spaces(text: str) -> str:
    total_spaces = text.count(' ')
    words        = text.split()
    word_count   = len(words)

    if word_count <= 1:
        return (words[0] if words else "") + (' ' * total_spaces)

    gap_count      = word_count - 1
    spaces_per_gap = total_spaces // gap_count
    remainder      = total_spaces % gap_count
    gap_string     = ' ' * spaces_per_gap

    return gap_string.join(words) + (' ' * remainder)

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   
   368       47       21       17   
   369       51       23       27   
   370       50       18       19   
   371       46       21       18   
   372       51       19       15   


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

  Week      Guests       Contributions       Languages   
   368       14       80       25   
   369       16       86       26   
   370       12       50       19   
   371       12       68       23   
   372       15       73       22   

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     (4375)
 2. Rust       (1151)
 3. C          (1024)
 3. Ruby       (903)
 5. Haskell    (897)
 6. Lua        (892)
 7. C++        (716)
 8. Go         (684)
 9. JavaScript (639)
10. Java       (532)

Blogs with Creative Title


1. Spaces at Large by Arne Sommer.

2. Regular Sub-Gaps by Jorg Sommrey.

3. Very Stringish by Matthias Muth.

4. Empty Substrings and Empty Spaces by Packy Anderson.

5. Strings of strings by Peter Campbell Smith.

6. Space is the Largest Place by Roger Bell_West.

7. Distant spaces by Simon Green.


GitHub Repository Stats


1. Commits: 49,533 (+126)

2. Pull Requests: 14,074 (+37)

3. Contributors: 278

4. Fork: 349

5. Stars: 212



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

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

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"

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))

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 17th May 2026.