Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #296 ("String Compression & Matchstick Squares")
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-11-10 through 2024-11-16 is #296. The tasks for challenge #296 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 296-1: String Compression Submitted by: Mohammad Sajid Anwar You are given a string of alphabetic characters, $chars. Write a script to compress the string with run-length encoding, as shown in the examples. A compressed unit can be either a single character or a count followed by a character. BONUS: Write a decompression function. Example 1: Input: $chars = "abbc" Output: "a2bc" Example 2: Input: $chars = "aaabccc" Output: "3ab3c" Example 3: Input: $chars = "abcc" Output: "ab2c" Since this problem involves an input consisting of a string of character