The Weekly Challenge: 388

4 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: Dyck Words

10. TASK #2: Secret Santa

HEADLINES


Welcome to the Week #388 of The Weekly Challenge.

Thank you, Roger Bell_West, for suggesting quality challenge. I request Team PWC to keep sharing new challenges.

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

Perl: source code


sub min_steps {
    my ($str) = @_;
    my $steps = 0;
    $steps++ while $str =~ s/01/10/g;
    return $steps;
}

Raku: source code


sub min-steps(Str $str is copy) {
    my $steps = 0;
    $steps++ while $str ~~ s:g/01/10/;
    return $steps;
}

Python: source code


def min_steps(s: str) -> int:
    steps = 0
    while "01" in s:
        s = re.sub(r"01", "10", s)
        steps += 1
    return steps

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   
   383       46       21       16   
   384       45       19       13   
   385       44       21       14   
   386       41       17       13   
   387       36       16       12   


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

  Week      Guests       Contributions       Languages   
   383       12       32       11   
   384       12       36       12   
   385       14       39       14   
   386       12       30       10   
   387       11       26       10   

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     (4570)
 2. Rust       (1214)
 3. C          (1060)
 4. Haskell    (947)
 5. Ruby       (935)
 6. Lua        (919)
 7. C++        (746)
 8. Go         (728)
 9. JavaScript (648)
10. Java       (532)

Blogs with Creative Title


1. String the Atoms by Arne Sommer.

2. Binary Chemistry by Jorg Sommrey.

3. Regex Man Hates Atom Man by Packy Anderson.

4. Ones and atoms by Peter Campbell Smith.

5. Only Binary Is Rational by Roger Bell_West.

6. Rearranging Atoms by Simon Green.

GitHub Repository Stats


1. Commits: 51,046 (+75)

2. Pull Requests: 14,597 (+29)

3. Contributors: 282

4. Fork: 353

5. Stars: 219


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

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

Task 1: Dyck Words

Submitted by: Roger Bell_West

A Dyck Word of order $n is a string of length 2x$n consisting of $n ‘U’ (Up) characters and $n ‘D’ (Down) characters such that no initial prefix of the string contains more ‘D’s than ‘U’s.

Write a script to return a list of all valid Dyck words of length 2x$n, sorted in lexicographical (alphabetical) order.

Example 1

Input: $n = 1
Output: ("UD")

Example 2

Input: $n = 2
Output: ("UDUD","UUDD")

Example 3

Input: $n = 3
Output: ("UDUDUD", "UDUUDD", "UUDDUD", "UUDUDD", "UUUDDD")

Example 4

Input: $n = 0
Output: ("")

Example 5

Input: $n = 4
Output: ("UDUDUDUD", "UDUDUUDD", "UDUUDDUD", "UDUUDUDD", "UDUUUDDD",
         "UUDDUDUD", "UUDDUUDD", "UUDUDDUD", "UUDUDUDD", "UUDUUDDD",
         "UUUDDDUD", "UUUDDUDD", "UUUDUDDD", "UUUUDDDD")

Task 2: Secret Santa

Submitted by: Roger Bell_West

A company with $n employees is running a Secret Santa exchange. Each employee buys one gift and receives one gift.

Write a script to return the total number of valid gift assignments where no employee receives the gift they originally bought (i.e., employee $i must not be assigned gift $i).

Example 1

Input: $n = 1
Output: 0

Only 1 participant exists. They would have to receive their own gift, which is invalid.

Example 2

Input: $n = 2
Output: 1

Participants 1 and 2 must swap gifts ([2, 1]).

Example 3

Input: $n = 3
Output: 2

The 2 valid gift arrays where array[i] is who person i+1 receives from:
[2, 3, 1]
[3, 1, 2]

Example 4

Input: $n = 4
Output: 9

The 9 valid arrays are:
[2, 1, 4, 3], [2, 3, 4, 1], [2, 4, 1, 3],
[3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1],
[4, 1, 2, 3], [4, 3, 1, 2], [4, 3, 2, 1],

Example 5

Input: $n = 5
Output: 44

There are 44 valid permutations out of 5! = 120 total possible arrangements.

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 30th August 2026.