The Weekly Challenge: 396

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: Finishing Order

10. TASK #2: Trionic Array

HEADLINES


Welcome to the Week #396 of The Weekly Challenge.

The dull and dark weather in London is back. Although it is the start of festive season but I hate it. You hardly get sun during this period, specially Nov/Dec/Jan. I had to make an extra effort to motivate myself. The December month is still OK as we get Christmas break to spend time with family and friends. November and post Christmas January is very boring and dull.

The weekly challenge is the only lifeline for me. It keeps me busy. Team PWC weekly push gives me lots of energy. I am also looking forward to London Perl Workshop 2026. Anyone coming to the event? Please let me know, we can meet and greet. Last year, I met Arne Sommer by chance.

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

Perl: source code


sub complex_multiply($x, $y) {
    my ($a, $b) = $x =~ /(-?\d+)\+?\(?(-?\d+)\)?i/;
    my ($c, $d) = $y =~ /(-?\d+)\+?\(?(-?\d+)\)?i/;
    my ($r, $i) = ($a * $c - $b * $d, $a * $d + $b * $c);
    return "$r" . ($i < 0 ? "+($i)i" : "+${i}i");
}

Raku: source code


sub complex-multiply($x, $y) {
    my ($a, $b) = extract_coeffs($x);
    my ($c, $d) = extract_coeffs($y);
    my ($r, $i) = ($a * $c - $b * $d, $a * $d + $b * $c);
    return "$r" ~ ($i < 0 ?? "+($i)i" !! "+{$i}i");
}

sub extract_coeffs($str) {
    $str ~~ m:P5/(-?\d+)\+?\(?(-?\d+)\)?i/;
    return ($/[0].Int, $/[1].Int);
}

Python: source code


def complex_multiply(x, y):
    m1 = re.search(r"(-?\d+)\+?\(?(-?\d+)\)?i", x)
    m2 = re.search(r"(-?\d+)\+?\(?(-?\d+)\)?i", y)
    a, b = int(m1.group(1)), int(m1.group(2))
    c, d = int(m2.group(1)), int(m2.group(2))

    r = a * c - b * d
    i = a * d + b * c

    return f"{r}+({i})i" if i < 0 else f"{r}+{i}i"

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   
   391       41       20       17   
   392       41       21       15   
   393       41       20       15   
   394       36       18       12   
   395       32       19       12   


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

  Week      Guests       Contributions       Languages   
   391       11       51       11   
   392       13       47       16   
   393       13       65       25   
   394       10       40       16   
   395       10       49       19   

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     (4675)
 2. Rust       (1247)
 3. C          (1077)
 4. Haskell    (969)
 5. Ruby       (952)
 6. Lua        (936)
 7. C++        (760)
 8. Go         (733)
 9. JavaScript (660)
10. Java       (532)

Blogs with Creative Title


1. Complex Squares by Arne Sommer.

2. Complex Squares by Jorg Sommrey.

3. Complex Squares by Matthias Muth.

4. There was magic abroad in the air… by Packy Anderson.

5. Complex words by Peter Campbell Smith.

6. Words are Complex by Roger Bell_West.

7. The complex square by Simon Green.

GitHub Repository Stats


1. Commits: 51,725 (+71)

2. Pull Requests: 14,835 (+23)

3. Contributors: 281

4. Fork: 353

5. Stars: 221


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

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

Task 1: Finishing Order

Submitted by: Mohammad Sajid Anwar

You are given two array of integers, @order and @friends.

The @order (size n) contains every integer from 1 to n exactly once. The @friends contains ID in sorted in strictly increasing order.

Write a script to return the array containing IDs in finishing order.

Example 1

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

ID 1 finished 2nd.
ID 4 finished 3rd.
ID 2 finished 4th.

Example 2

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

ID 5 finished 1st.
ID 3 finished 3rd.
ID 1 finished 5th.

Example 3

Input: @order = (2, 4, 1, 3)
       @friends = (1, 2, 3, 4)
Output: (2, 4, 1, 3)

ID 2 finished 1st.
ID 4 finished 2nd.
ID 1 finished 3rd.
ID 3 finished 4th.

Example 4

Input: @order = (4, 1, 3, 2)
       @friends = (3)
Output: (3)

Example 5

Input: @order = (1, 3, 2, 6, 5, 4)
       @friends = (1, 2, 3)
Output: (1, 3, 2)

ID 1 finished 1st.
ID 3 finished 2nd.
ID 2 finished 3rd.

Task 2: Trionic Array

Submitted by: Mohammad Sajid Anwar

You are given an array of integer.

Write a script to return true if the given array is Trionic otherwise return false.

An array is trionic if there exist indices 0 < p < q < n − 1 such that arr[0…p] is strictly increasing, arr[p…q] is strictly decreasing, and arr[q…n − 1] is strictly increasing.

Example 1

Input: @arr = (1, 3, 5, 4, 2, 6, 8)
Output: true

Choose p = 2 and q = 4
$arr[0..2] = (1, 3, 5) (strictly increasing)
$arr[2..4] = (5, 4, 2) (strictly decreasing)
$arr[4..6] = (2, 6, 8) (strictly increasing)

Valid indices: 0 < p (2) < q (4) < n-1 (6).

Example 2

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

The first segment (1, 4, 4) contains duplicate adjacent values, so it is not strictly increasing.
No valid p and q exist to satisfy all three strictly monotonic conditions.

Example 3

Input: @arr = (2, 10, 3, 1, 9)
Output: true

Choose p = 1 and q = 3.
$arr[0..1] = (2, 10)    (strictly increasing)
$arr[1..3] = (10, 3, 1) (strictly decreasing)
$arr[3..4] = (1, 9)     (strictly increasing)

Example 4

Input: @arr = (1, 2, 3, 4, 3, 2, 1)
Output: false

This is a standard mountain array (strictly increasing, then strictly decreasing).
There is no second valley (q) that transitions back into a strictly increasing third segment before reaching the end of the array.

Example 5

Input: @arr = (1, 3, 6, 4, 2, 7, 8, 4)
Output: false

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 25th October 2026.