Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #396 (“Finishing Order” and “Trionic Array”)

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge

The Weekly Challenge for the week of 2026-10-19 through 2026-10-25 is #396.

The tasks for challenge #396 are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 396-1: Finishing Order
Submitted by: Mohammad Sajid Anwar
You are given two array of integers, @order and @friends.
@order (size n) contains every integer from 1 to n exactly once.
@friends contains IDs in sorted in strictly increasing order.
Write a script to return the IDs in finishing order.

To solve this problem, I use a hash %h with keys being the values of @order and values being the corresponding indexes of @order. I then just sort @friends by {$h{$a}<=>$h{$b}}.

Robbie Hatley's Perl Solution to The Weekly Challenge 396-1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 396-2: Trionic Array
Submitted by: Mohammad Sajid Anwar
You are given an array of integers. 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.

To solve this problem, I'll simply keep a list of changes of direction. That list should be 'UDU'. If it's anything else, the array is not trionic.

Robbie Hatley's Perl Solution to The Weekly Challenge 396-2

That's it for challenge 396; see you on challenge 397!

Comments

Popular posts from this blog

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #357 (“Kaprekar Constant” and “Unique Fraction Generator”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #351 (“Special Average” and “Arithmetic Progression”)

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #356 (“Kolakoski Sequence” and “Who Wins”)