Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #357 (“Kaprekar Constant” and “Unique Fraction Generator”)
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...