Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #371 (“Missing Letter” and “Subset Equilibrium”)
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-04-27 through 2026-05-03 is #371. The tasks for challenge #371 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 371-1: Missing Letter
Submitted by: Reinier Maliepaard
You are given a sequence of 5 lowercase letters, with one letter
replaced by ‘?’. Each letter maps to its position in the alphabet
(‘a = 1’, ‘b = 2’, …, ‘z = 26’). The sequence follows a repeating
pattern of step sizes between consecutive letters. The pattern is
either a constant step (e.g., ‘+2, +2, +2, +2’) or a simple
alternating pattern of two distinct steps (e.g., ‘+2, +3, +2, +3’).
Example inputs: ("ac?gi", "ad?jm", "ae?mq", "acf?k", "beg?l")
Expected outputs: e g i h j
Specifying alternating intervals which may-or-may-not be the same is the same as specifying one "even-index" interval and one "odd-index" interval which may-or-may-not be the same. So we need only find-and-record the first even-index interval, then find-and-record the first odd-index interval, then note the index of the ? mark, then add the appreciate interval to the value of the index immediately before the ? to get our final answer.
Robbie Hatley's Perl Solution to The Weekly Challenge 371-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 371-2: Subset Equilibrium Submitted by: Mohammad Sajid Anwar You are given an array of numbers. Write a script to find all proper subsets with more than one element where the sum of elements equals the sum of their 1-based indices.
I can't see a "clever" way to do this, so I'll generate all combinations of i elements from 0..n-1 for i from 2 to n-1, then see which ones have value sums equal to 1-based index sums.
Robbie Hatley's Perl Solution to The Weekly Challenge 371-2
That's it for challenge 371; see you on challenge 372!
Comments
Post a Comment