Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #394 (“Alternate Case” and “Alternating Vowels Consonants”)

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-05 through 2026-10-11 is #394.

The tasks for challenge #394 are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 394-1: Alternate Case
Submitted by: Mohammad Sajid Anwar
You are given a string containing an equal number of uppercase
and lowercase English letters. Write a script to the minimum
number of adjacent character swaps needed to turn the given
string into an alternate case string.

We need not perform any swaps at all. Instead, we need only note that there are only two possible ending patterns of uppercase indices: (0, 2, 4,...) or (1, 3, 5,...). We need only count the costs to achieve each of those patterns. And those costs will be the sums of the distances each upper-case letter will have to move to go from its current position to its new position in (0, 2, 4,...) or (1, 3, 5,...). Then just return the lesser of those two costs.

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 394-2: Alternating Vowels Consonants
Submitted by: Mohammad Sajid Anwar
You are given three strings containing English alphabetic
characters. Find all the longest contiguous substrings common to
all three strings that strictly alternate between vowels and
consonants.

I'll make a hash of alternating substrings keyed by substring with value [occurrences_bitmask,length], double-sort descending by occurrences_bitmask then length, then return sorted list of longest ones.

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

That's it for challenge 394; see you on challenge 395!

Comments

Popular posts from this blog

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #347 (“Format Date” and “Format Phone”)

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 #357 (“Kaprekar Constant” and “Unique Fraction Generator”)