The Weekly Challenge: 390

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

10. TASK #2: Order Characters

HEADLINES


Welcome to the Week #390 of The Weekly Challenge.

Today is the first Monday of the month and time to announce the next Champion of the Month. With great pleasure, I announce Robbie Hatley as the next champion. He currently ranked #25 with total points, 1100. As of today, he shared 376 solutions in Perl and 174 blog posts. Congratulation Robbie.

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

Perl: source code


sub reconstruct_melody ($composer, $notes, $perm) {
    my @reordered;
    @reordered[ map { $_ - 1 } @$perm ] = @$notes;
    return uc($composer) . ' => ' . join(' ', @reordered);
}

Raku: source code


sub reconstruct-melody($composer, $notes, $perm) {
    my @reordered;
    @reordered[ $perm.map(* - 1) ] = @$notes;
    return "{$composer.uc} => {@reordered.join(' ')}";
}

Python: source code


def reconstruct_melody(composer, notes, perm):
    reordered = [None] * len(notes)
    indices   = map(lambda x: x - 1, perm)

    def assign(idx_note):
        reordered[idx_note[0]] = idx_note[1]

    list(map(assign, zip(indices, notes)))
    return f"{composer.upper()} => {' '.join(reordered)}"

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   
   385       44       21       14   
   386       41       17       13   
   387       36       16       12   
   388       39       19       15   
   389       41       18       14   


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

  Week      Guests       Contributions       Languages   
   385       14       39       14   
   386       12       30       10   
   387       11       26       10   
   388       12       70       25   
   389       13       70       23   

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     (4602)
 2. Rust       (1222)
 3. C          (1067)
 4. Haskell    (953)
 5. Ruby       (943)
 6. Lua        (927)
 7. C++        (750)
 8. Go         (732)
 9. JavaScript (652)
10. Java       (532)

Blogs with Creative Title


1. ZigZag Reorder by Arne Sommer.

2. ZigZag Melodies by Jorg Sommrey.

3. Zig Zag Melodies by Packy Anderson.

4. Musical zigzags by Peter Campbell Smith.

5. Zigzag Reorder by Roger Bell_West.

6. Zigzag notes by Simon Green.

GitHub Repository Stats


1. Commits: 51,224 (+102)

2. Pull Requests: 14,661 (+35)

3. Contributors: 282

4. Fork: 352

5. Stars: 220 (+1)


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

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

Task 1: Decode String

Submitted by: Mohammad Sajid Anwar

You are given an encoded string.

Write a script to return the decoded string of the given encoded string.

The encoding rule is: K[encoded_string], where the encoded_string inside the square brackets is repeated exactly K > 0 times.

Example 1

Input: $str = "2[3[a]]"
Output: "aaaaaa"

3[a]    => aaa
2[3[a]] => aaa aaa

Example 2

Input: $str = "10[a]"
Output: "aaaaaaaaaa"

Example 3

Input: $str = "a2[b]c3[d]e"
Output: "abbcddde"

Example 4

Input: $str = "2[a2[b]c]"
Output: "abbcabbc"

Example 5

Input: $str = "1[a]2[b3[c]]"
Output: "abcccbccc"

Task 2: Order Characters

Submitted by: Mohammad Sajid Anwar

You are given a string $s (containing only alphabetic characters) and an integer $k > 0.

Write a script to choose one of the first $k letters of given string and append it at the end of the string. You keep doing this until you have lexicographically smallest string and return the string.

Example 1

Input: $str = "dbca", $k = 1
Output: "adbc"

Move 1: "bcad"
Move 2: "cadb"
Move 3: "adbc"

Example 2

Input: $str = "geeks", $k = 2
Output: "eegks"

First 2 letters: "g", "e"

Move 1: "gekse" (move second letter "e")
Move 2: "gksee" (move second letter "e")
Move 3: "kseeg"
Move 4: "seegk"
Move 5: "eegks"

Example 3

Input: $str = "cbaed", $k = 3
Output: "abcde"

First 3 letters: "c", "b", "a"

Move 1: "cbeda"  (move "a")
Move 2: "cedab"  (move "b")
Move 3: "edabc"  (move "c")
Move 4: "eabcd"  (move "d")
Move 5: "abcde"  (move "e")

Example 4

Input: $str = "fedcba", $k = 4
Output: "abcdef"

First 4 letters: "f", "e", "d", "c"

Move 1: "fdcbae" (move "e")
Move 2: "dcbaef" (move "f")
Move 3: "dcbefa" (move "a")
Move 4: "dcefab" (move "b")
Move 5: "defabc" (move "c")
Move 6: "efabcd" (move "d")
Move 7: "fabcde" (move "e")
Move 8: "abcdef" (move "f")

Example 5

Input: $str = "perl", $k = 1
Output: "erlp"

Move 1: "erlp" (move "p")

Example 6

Input: $str = "oloolooo", $k = 1
Output: "looloooo"

Example 7

Input: $str = "oloooolo", $k = 1
Output: "looloooo"

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