Posts

Showing posts from January, 2026

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #357 (“Kaprekar Constant” and “Unique Fraction Generator”)

Image
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-01-19 through 2026-01-25 is #357. The tasks for challenge #357 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 357-1: Kaprekar Constant Submitted by: Mohammad Sajid Anwar Write a function that takes a 4-digit integer and returns how many iterations of the following algorithm are required to reach Kaprekar’s constant (6174). (For more information about Kaprekar's Constant, see "https://en.wikipedia.org/wiki/6174".) 1. Select any four-digit number that has at least two different digits (leading zeros are allowed). 2. Create two new four-digit numbers by arranging the original digits in a.) ascending and b.) descending order (adding leading zeros if necessary). 3. Subtract...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #356 (“Kolakoski Sequence” and “Who Wins”)

Image
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-01-12 through 2026-01-18 is #356. The tasks for challenge #356 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 356-1: Kolakoski Sequence Submitted by: Mohammad Sajid Anwar You are given an integer, $int > 3. Write a script to generate the Kolakoski Sequence of given length $int and return the count of 1 in the generated sequence. Please follow the wikipedia page for more informations. Example #1: Input: $int = 4 Output: 2 (1)(22)(11)(2) => 1221 Example #2: Input: $int = 5 Output: 3 (1)(22)(11)(2)(1) => 12211 Example #3: Input: $int = 6 Output: 3 (1)(22)(11)(2)(1)(22) => 122112 Example #4: Input: $int = 7 Output: 4 (1)(22)(11)(2)(1)(22)(1) => 1221121 Example #5: Input: $int = 8 Output: 4 (1)(2...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #355 (“Thousand Separator” and “Mountain Array”)

Image
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-01-05 through 2026-01-11 is #355. The tasks for challenge #355 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 355-1: Thousand Separator Submitted by: Mohammad Sajid Anwar You are given a positive integer, $int. Write a script to add thousand separator, "," and return as string. Example #1: Input: $int = 123 Output: "123" Example #2: Input: $int = 1234 Output: "1,234" Example #3: Input: $int = 1000000 Output: "1,000,000" Example #4: Input: $int = 1 Output: "1" Example #5: Input: $int = 12345 Output: "12,345" I'll write a subroutine which splits each integer to its decimal digits, then pops each digit from the right end of the array and append...