Posts

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #402 (“Letters Only Hex” and “Circular String Rotations”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two tasks, 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-30 through 2026-12-06 is #402. The tasks for this challenge are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 402-1: Letters Only Hex Submitted by: Mohammad Sajid Anwar You are given a string representing a decimal integer >= 1 without leading zeros. Write a script that to convert the given string into its uppercase hexadecimal representation. Replace every digit ‘0’ with the letter ‘O’, also replace every digit ‘1’ with the letter ‘I’. The resulting string should only contain characters: ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘I’, and ‘O’. To solve this problem, I'll use the excellent base-conversion routines in CPAN module "Math::BigInt" to make the hex version, use "y" to transliterate al...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #400 (“Largest Interval” and “Minimum Genetic Mutation”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two tasks, 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-09 through 2026-11-15 is #400. The tasks for this challenge are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 400-1: Largest Interval Submitted by: Ali Moradi You are given a positive integer. Write a script that generates a sequence of integers from 1 to given positive integer, filtering out any numbers that contain repeating digits (e.g., 11, 99, 100, and 101 are excluded) and return the biggest jump. We don't need to store the integers in an array; we need only keep track of "longest interval seen so far". Robbie Hatley's Perl Solution to The Weekly Challenge 400-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 400-2: Minimum Genetic Mutation ...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #399 (“Longest Repeating Character” and “Longest Absolute Path”)

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-11-09 through 2026-11-15 is #399. The tasks for this challenge are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 399-1: Longest Repeating Character Submitted by: Mohammad Sajid Anwar You are given a string str and an integer k > 0. Write a script to choose any character of str and change it to another character. You may perform this operation up to k times. Return the length of the longest reachable substring of a single letter. Musical accompaniment: Paul McCartney's "Long And Winding Road". To solve this problem, I'll generate every substring of the string, then calculate the aomac (Abundance Of Most-Abundant Character) for each substring. Then if length - aomac is less-than-or-equal-to...

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

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-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 ~~~~~~~~~~~~~~~~~~~~~~...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #397 (“Absent Smallest Positive” and “Binary Reflection”)

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-10-26 through 2026-11-01 is #397. The tasks for challenge #397 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 397-1: Absent Smallest Positive Submitted by: Mohammad Sajid Anwar You are given an array of integers. Write a script to return the smallest absent positive integer such that it is strictly greater than the average of all elements in the given array. I first hash the input array @$aref to %hash, then store it's average in $avg. I then set a variable $asp to the floor of $avg plus 1, or to 1, whichever is greater. I then repeatedly increment $asp for so long as $asp is in %hash. Then I simply return $asp. That yields "the smallest positive integer which is strictly-greater than the average o...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #396 (“Finishing Order” and “Trionic 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-10-19 through 2026-10-25 is #396. The tasks for challenge #396 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 396-1: Finishing Order Submitted by: Mohammad Sajid Anwar You are given two array of integers, @order and @friends. @order (size n) contains every integer from 1 to n exactly once. @friends contains IDs in sorted in strictly increasing order. Write a script to return the IDs in finishing order. To solve this problem, I use a hash %h with keys being the values of @order and values being the corresponding indexes of @order. I then just sort @friends by {$h{$a}<=>$h{$b}}. Robbie Hatley's Perl Solution to The Weekly Challenge 396-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #016 (“Pythagoras Pie Puzzle” and “Validating Bitcoin Addresses”)

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 tasks for challenge #016 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 016-1: Pythagoras Pie Puzzle Proposed by Jo Christian Oterhals. At a party a pie is to be shared by 100 guests. The first guest gets 1% of the pie, the second guest gets 2% of the remaining pie, the third gets 3% of the remaining pie, the fourth gets 4%, and so on. Write a script that figures out which guest gets the largest piece of pie. I simply performed the calculations described. What happened, I found surprising. Robbie Hatley's Perl Solution to The Weekly Challenge 016-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 016-2: Validating Bitcoin Addresses Write a script to validate a given bitcoin address. Most Bitcoin addr...