Posts

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

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #354 (“Min Abs Diff” and “Shift Grid”)

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 2025-12-29 through 2026-01-04 is #354. The tasks for challenge #354 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 354-1: Min Abs Diff Submitted by: Mohammad Sajid Anwar You are given an array of distinct integers. Write a script to find all pairs of elements with the minimum absolute difference. Rules (a,b): 1: a, b are from the given array. 2: a < b 3: b - a = min abs diff any two elements in the given array # Example inputs and corresponding expected outputs: ( # Example #1 input: [4, 2, 1, 3], # Expected output: [1, 2], [2, 3], [3, 4] # Example #2 input: [10, 100, 20, 30], # Expected output: [10, 20], [20, 30] # Example #3 input: [-5, -2, 0, 3], # Expected output: [-2, 0] # E...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #353 (“Max Words” and “Validate Coupon”)

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 2025-12-22 through 2025-12-28 is #353. The tasks for challenge #353 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 353-1: Max Words Submitted by: Mohammad Sajid Anwar You are given an array of sentences. Write a script to return the maximum number of words that appear in a single sentence. Example #1: Input: ("Hello world", "This is a test", "Perl is great") Output: 4 Example #2: Input: ("Single") Output: 1 Example #3: Input: ("Short", "This sentence has six words in total", "A B C", "Just four words here") Output: 7 (The second sentence lied.) Example #4: Input: ("One", ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #352 (“Match String” and “Binary Prefix”)

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 2025-12-15 through 2025-12-21 is #352. The tasks for challenge #352 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 352-1: Match String Submitted by: Mohammad Sajid Anwar You are given an array of strings. Write a script to return all strings that are a substring of another word in the given array in the order they occur. Example #1: Input: ("cat", "cats", "dog", "dogcat", "dogcat", "rat", "ratcatdogcat") Output: ("cat", "dog", "dogcat", "rat") Example #2: Input: ("hello", "hell", "world", "wor", "ellow", "elloworld") Output: ("hell", ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #351 (“Special Average” and “Arithmetic Progression”)

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 2025-12-08 through 2025-12-14 is #351. The tasks for challenge #351 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 351-1: Special Average Submitted by: Mohammad Sajid Anwar You are given an array of integers. Write a script to return the average excluding the minimum and maximum of the given array. Example #1: Input: @ints = (8000, 5000, 6000, 2000, 3000, 7000) Output: 5250 Min: 2000 Max: 8000 Avg: (3000+5000+6000+7000)/4 = 21000/4 = 5250 Example #2: Input: @ints = (100_000, 80_000, 110_000, 90_000) Output: 95_000 Min: 80_000 Max: 110_000 Avg: (100_000 + 90_000)/2 = 190_000/2 = 95_000 Example #3: Input: @ints = (2500, 2500, 2500, 2500) Output: 0 Min: 2500 Max: 2500 Avg: 0 Example #4: Input: @ints = (2000) Output...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #350 (“Good Substrings” and “Shuffle Pairs”)

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 2025-12-01 through 2025-12-07 is #350. The tasks for challenge #350 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 350-1: Good Substrings Submitted by: Mohammad Sajid Anwar You are given a string. Write a script to return the number of good substrings of length three in the given string. A string is good if there are no repeated characters. Example #1: Input: $str = "abcaefg" Output: 5 Good substrings of length 3: abc, bca, cae, aef and efg Example #2: Input: $str = "xyzzabc" Output: 3 Good substrings of length 3: "xyz", "zab" and "abc" Example #3: Input: $str = "aababc" Output: 1 Good substrings of length 3: "abc" Example #4: Input: $str = ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #349 (“Power String” and “Meetings Point”)

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 2025-11-24 through 2025-11-30 is #349. The tasks for challenge #349 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 349-1: Power String Submitted by: Mohammad Sajid Anwar You are given a string. Write a script to return the power of the given string. The power of the string is the maximum length of a non-empty substring that contains only one unique character. Example #1: Input: $str = "textbook" Output: 2 Breakdown: "t", "e", "x", "b", "oo", "k" The longest substring with one unique character is "oo". Example #2: Input: $str = "aaaaa" Output: 5 Example #3: Input: $str = "hoorayyy" Output: 3 Breakdown: "h"...