Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #383 (“Similar List” and “Nearest RGB”)

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-07-20 through 2026-07-26 is #383. If anyone is wondering what happened to 377 through 382, I've been quite busy the last two months adjusting to my life as a "newly-retired person", so I haven't had the attention for The Perl Weekly Challenge Club. But after a 42-day absence, I'm back! I may eventually solve the skipped challenges and post my results here, but for now, here is Challenge 383.

The tasks for challenge #383 are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 383-1: Similar List
Submitted by: Mohammad Sajid Anwar
You are given two lists of strings and a list of "similar-words groups".
Write a script to find out if the two word lists are "similar" with the
help the "similar-words groups".

To solve this problem, I made a hash called "sim" containing the information from the "similar words maps" and also entries indicating that every word in every string is also "similar" to itself.

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 383-2: Nearest RGB
Submitted by: Mohammad Sajid Anwar
You are given a 6-digit hex color. Write a script to round the RGB
channels to the nearest "web-safe value" and return the nearest "safe"
RGB color. "web-safe" channel values are:
   0x00 (  0)
   0x33 ( 51)
   0x66 (102)
   0x99 (153)
   0xCC (204)
   0xFF (255)

To solve this problem, I wrote two subroutines: "snap", which snaps any real number to the closest web-safe channel value; and "safe", which gives the web-safe color number for each original color number (by calling "snap" once for each of the three channel values then combining and returning the result).

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

That's it for challenge 383; see you on challenge 384!

Comments

Popular posts from this blog

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #334 (“Range Sum” and “Nearest Valid Point”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #336 (“Equal Group” and “Final Score”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #332 (“Binary Date” and “Odd Letters”)