Posts

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

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #394 (“Alternate Case” and “Alternating Vowels Consonants”)

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-05 through 2026-10-11 is #394. The tasks for challenge #394 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 394-1: Alternate Case Submitted by: Mohammad Sajid Anwar You are given a string containing an equal number of uppercase and lowercase English letters. Write a script to the minimum number of adjacent character swaps needed to turn the given string into an alternate case string. We need not perform any swaps at all. Instead, we need only note that there are only two possible ending patterns of uppercase indices: (0, 2, 4,...) or (1, 3, 5,...). We need only count the costs to achieve each of those patterns. And those costs will be the sums of the distances each upper-case letter will have to move to g...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #393 (“Pythagoras Multiplied” and “Prime Step”)

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-09-28 through 2026-10-04 is #393. The tasks for challenge #393 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 393-1: Pythagoras Multiplied Submitted by: Ulrich Rieke You are given a positive integer n. Find the number of all positive integer triplets (a, b, c) so that a^2 + b^2 = c^2 and a, b and c are integers <= n. I'll use a pair of nested ranged foreach loops to check all possible (c,a) pairs to see which (if any) need b values which are positive integers in order for "$a*$a + $b*$b == $c*$c" to be true. Robbie Hatley's Perl Solution to The Weekly Challenge 393-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 393-2: Prime Step Submitted b...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #392 (“Convert Palindrome” and “Words Length Product”)

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-09-21 through 2026-09-27 is #392. The tasks for challenge #392 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 392-1: Convert Palindrome Submitted by: Mohammad Sajid Anwar Write a script to convert a given string to a palindrome by concatenating the minimum number of characters to its left. To solve this problem, I realized that to minimize letters added, I should look for the longest palindromic prefix within the word, then just tack the reversed remainder to the word's left. Robbie Hatley's Perl Solution to The Weekly Challenge 392-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 392-2: Words Length Product Submitted by: Mohammad Sajid Anwar You are give...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #391 (“Array Median” and “Arrange Box”)

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-09-14 through 2026-09-20 is #391. The tasks for challenge #391 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 391-1: Array Median Submitted by: Mohammad Sajid Anwar You are given two sorted arrays of numbers. Write a script to merge the two given sorted arrays and return the median of the merged array. "Merging" is just "my @a3 = sort {$a<=>$b} (@$a1, @$a2);". (Merge Sort won't work, because the problem doesn't state whether the arrays are increasing, decreasing, or going in opposite directions. So I force increasing.) "Median" depends on parity. For an odd number of elements, the median is the middle element. For an even number of elements, the median is one ha...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #390 (“Decode String” and “Order Characters”)

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-09-07 through 2026-09-13 is #390. The tasks for challenge #390 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 390-1: Decode String Submitted by: Mohammad Sajid Anwar You are given an encoded string. Write a script to return the decoded string of the given encoded string. The encoding rule is: K[encoded_string], where the encoded_string inside the square brackets is repeated exactly K > 0 times. I'll use a Perl s/// operator in a while loop to decode innermost bracket pairs for as long as some exist, thus solving the problem from the inside out. Robbie Hatley's Perl Solution to The Weekly Challenge 390-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 39...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #389 (“Reorder Notes” and “ZigZag Subarray”)

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-08-31 through 2026-09-07 is #389. The tasks for challenge #389 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 389-1: Reorder Notes Submitted by: Reinier Maliepaard You are given an array [composer, notes, permutation]. Reconstruct the melody by using each permutation value as the destination position of the corresponding note. Use no explicit for, foreach, or while loops. Output each result as "COMPOSER => reordered notes". ASSUMPTION: Input is valid; the notes array and permutation array have identical lengths, and the permutation contains each position from 1 to N exactly once. I solved this by assigning the original array to an initially-empty array "sliced" by the permutation numb...