The Weekly Challenge: 389

6 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: Reorder Notes

10. TASK #2: ZigZag Subarray

HEADLINES


Welcome to the Week #389 of The Weekly Challenge.

Thank you, Reinier Maliepaard and Roger Bell_West for the fun challenges this week.

Happy to see, Abigail, Roger Bell_West and Ulrich Rieke back with complete package solutions. Thank you to all regular contributors as well.

Today is the last holiday before school opens. I hate the morning school run.

I am being very lazy today, it delays the launch of weekly challenge, sorry :-(

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

Perl: source code


sub dyck_words($n, $u = 0, $d = 0, $path = '') {
    return $path if $u == $n && $d == $n;
    return (
        ($d < $u ? dyck_words($n, $u, $d + 1, $path . 'D') : ()),
        ($u < $n ? dyck_words($n, $u + 1, $d, $path . 'U') : ())
    );
}

Raku: source code


sub dyck-words($n, $u = 0, $d = 0, $path = '') {
    return ($path) if $u == $n && $d == $n;
    return (
        ($d < $u ?? dyck-words($n, $u, $d + 1, $path ~ 'D') !! ()),
        ($u < $n ?? dyck-words($n, $u + 1, $d, $path ~ 'U') !! ())
    ).flat;
}

Python: source code


def dyck_words(n, u=0, d=0, path=""):
    if u == n and d == n:
        return [path]

    res = []
    if d < u:
        res.extend(dyck_words(n, u, d + 1, path + "D"))
    if u < n:
        res.extend(dyck_words(n, u + 1, d, path + "U"))
    return res

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


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

  Week      Guests       Contributions       Languages   
   384       12       36       12   
   385       14       39       14   
   386       12       30       10   
   387       11       26       10   
   388       11       68       25   

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     (4583)
 2. Rust       (1218)
 3. C          (1064)
 4. Haskell    (949)
 5. Ruby       (939)
 6. Lua        (923)
 7. C++        (748)
 8. Go         (730)
 9. JavaScript (648)
10. Java       (532)

Blogs with Creative Title


1. Secret Dyck by Arne Sommer.

2. I Refuse to Indulge in the Obvious Jokes by Bob Lied.

3. Secret Words by Jorg Sommrey.

4. Dyck Santa by Matthias Muth.

5. Code of Many Colors by Packy Anderson.

6. Up and down the chimney by Peter Campbell Smith.

7. Secret Dyck by Roger Bell_West.

8. Secret Words by Simon Green.

GitHub Repository Stats


1. Commits: 51,122 (+76)

2. Pull Requests: 14,626 (+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 - 388 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 #388.

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

Task 1: Reorder Notes

Submitted by: Reinier Maliepaard

You are given an array [composer, notes, permutation], reconstruct the melody by using each permutation value as the destination position of the corresponding note. Use no explicit for, foreach, or while loops. Output each result as COMPOSER => reordered notes.

ASSUMPTION: Input is valid; the notes array and permutation array have identical lengths, and the permutation contains each position from 1 to N exactly once.

Example 1

Input: $melody = ['Bach', [qw(C D E F# G A B)], [7, 1, 6, 2, 5, 3, 4]]
Output: BACH => D F# A B G E C

Note 1 (C)  moves to position 7.
Note 2 (D)  moves to position 1.
Note 3 (E)  moves to position 6.
Note 4 (F#) moves to position 2.
Note 5 (G)  moves to position 5.
Note 6 (A)  moves to position 3.
Note 7 (B)  moves to position 4.

Example 2

Input: $melody = ['Beethoven', [qw(C D F# G Ab)], [1, 3, 5, 2, 4]]
Output: BEETHOVEN => C G D Ab F#

Note 1 (C)  stays at position 1.
Note 2 (D)  moves to position 3.
Note 3 (F#) moves to position 5.
Note 4 (G)  moves to position 2.
Note 5 (Ab) moves to position 4.

Example 3

Input: $melody = [ 'Brahms', [qw(C Db Eb F G Ab Bb C D)], [9, 3, 7, 1, 8, 5, 2, 6, 4] ]
Output: BRAHMS => F Bb Db D Ab C Eb G C

Example 4

Input: $melody = [ 'Bruckner', [qw(G F# Bb C D Eb F)], [4, 7, 2, 6, 1, 5, 3] ]
Output: BRUCKNER => D Bb F G Eb C F#

Example 5

Input: $melody = ['Berg', [qw(C#)], [1]]
Output: BERG => C#

Task 2: ZigZag Subarray

Submitted by: Roger Bell_West

You are given an array of integers.

Write a script to find the length of the longest contiguous subarray where the numbers alternate between strictly increasing and strictly decreasing (a ZigZag pattern).

A sequence of numbers $A = [a0, a1, …, ak]$ with length $k >= 1 is considered a ZigZag sequence if every adjacent pair alternates direction:

a_0 < a_1 > a_2 < a_3 > ...
OR
a_0 > a_1 < a_2 > a_3 < ...

NOTE: A single element (length 1) or any two distinct elements (length 2) are automatically valid ZigZag sequences. Equal adjacent numbers (e.g., 5, 5) break the pattern.

Example 1

Input: @nums = (9, 4, 2, 10, 7, 8, 8, 1, 9)
Output: 5

ZigZag subarray: (4, 2, 10, 7, 8)

Example 2

Input: @nums = (1, 7, 4, 9, 2, 5)
Output: 6

ZigZag subarray: (1, 7, 4, 9, 2, 5)

Example 3

Input: @nums = (1, 2, 3, 4, 5)
Output: 2

ZigZag subarray: (1, 2)

Example 4

Input: @nums = (4, 4, 4)
Output: 1

Example 5

Input: @nums = (10, 20, 15, 12, 18)
Output: 3

ZigZag subarray: (10, 20, 15)

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 6th September 2026.