Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #398 (“Divisible Average” and “String Difference”)

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-11-02 through 2026-11-08 is #398.

The tasks for challenge #398 are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 398-1: Divisible Average
Submitted by: Mohammad Sajid Anwar
You are given an array of positive integers. Write a script to
return the closest integer to the mean value of all even integers
that are divisible by 3. If none is divisible, return 0.

The phrase "even integers that are divisible by 3" is the same as "integers which are divisible by 6", so I need only test "0 == $int % 6", and if there are some of those, return "floor(mean(@ints)+0.5)", else 0.

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 398-2: String Difference
Submitted by: Mohammad Sajid Anwar
You are given an array of equal length strings. Write a script
to find the difference integer array of each word in the given
array. There will be one word with a different array; return
that word. Each words[i] can be converted into a difference
integer array difference[i] of length n - 1 where
difference[i][j] = words[i][j+1] - words[i][j]

The problem description assumes that the input data has been tailored to make the program's output come out as desired. I find that assumption unwarranted, so I'll elect to write the program such that it can accept any arrays of equal-length strings, whether there exist any words with unique difference arrays or not.

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

That's it for challenge 398; see you on challenge 399!

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”)