Posts

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #337 (“Count LE Others” and “Count Odds”)

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-09-01 through 2025-09-07 is #337 The tasks for challenge #337 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 337-1: Count LE Others Submitted by: Mohammad Sajid Anwar You are given an array of numbers, @num1. Write a script to return an array, @num2, where $num2[$i] is the count of all numbers in @num1 other than $num1[$i] which are less than or equal to $num1[$i]. Example #1: Input: @num1 = (6, 5, 4, 8) Output: (2, 1, 0, 3) Example #2: Input: @num1 = (7, 7, 7, 7) Output: (3, 3, 3, 3) Example #3: Input: @num1 = (5, 4, 3, 2, 1) Output: (4, 3, 2, 1, 0) Example #4: Input: @num1 = (-1, 0, 3, -2, 1) Output: (1, 2, 4, 0, 3) Example #5: Input: @num1 = (0, 1, 1, 2, 0) Output: (1, 3, 3, 4, 1) For each elemen...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #336 (“Equal Group” and “Final Score”)

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-08-25 through 2025-08-31 is #336 The tasks for challenge #336 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 336-1: Equal Group Submitted by: Mohammad Sajid Anwar You are given an array of integers. Write a script to return true if the given array can be divided into one or more groups: each group must be of the same size as the others, with at least two members, and with all members having the same value. Example #1: Input: @ints = (1,1,2,2,2,2) Output: true Groups: (1,1), (2,2), (2,2) Example #2: Input: @ints = (1,1,1,2,2,2,3,3) Output: false Groups: (1,1,1), (2,2,2), (3,3) Example #3: Input: @ints = (5,5,5,5,5,5,7,7,7,7,7,7) Output: true Groups: (5,5,5,5,5,5), (7,7,7,7,7,7) Example #4: Input: @ints ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #335 (“Common Characters” and “TicTacToe”)

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-08-18 through 2025-08-24 is #335 The tasks for challenge #335 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 335-1: Common Characters Submitted by: Mohammad Sajid Anwar You are given an array of words. Write a script to return all characters that is in every word in the given array including duplicates. Example #1: Input: @words = ("bella", "label", "roller") Output: ("e", "l", "l") Example #2: Input: @words = ("cool", "lock", "cook") Output: ("c", "o") Example #3: Input: @words = ("hello", "world", "pole") Output: ("l", "o") Example #4: Input: ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #334 (“Range Sum” and “Nearest Valid 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-08-11 through 2025-08-17 is #334 The tasks for challenge #334 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 334-1: Range Sum Submitted by: Mohammad Sajid Anwar You are given a list integers and pair of indices. Write a script to return the sum of integers between the given indices (inclusive). Example #1: Input: @ints = (-2, 0, 3, -5, 2, -1), $x = 0, $y = 2 Output: 1 Example #2: Input: @ints = (1, -2, 3, -4, 5), $x = 1, $y = 3 Output: -3 Example #3: Input: @ints = (1, 0, 2, -1, 3), $x = 3, $y = 4 Output: 2 Example #4: Input: @ints = (-5, 4, -3, 2, -1, 0), $x = 0, $y = 3 Output: -2 Example #5: Input: @ints = (-1, 0, 2, -3, -2, 1), $x = 0, $y = 2 Output: 1 This is just a matter of using "sum0...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #333 (“Straight Line” and “Duplicate Zeros”)

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-08-04 through 2025-08-10 is #333 The tasks for challenge #333 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 333-1: Straight Line Submitted by: Mohammad Sajid Anwar You are given a list of co-ordinates. Write a script to find out if the given points make a straight line. Example 1 Input: @list = ([2, 1], [2, 3], [2, 5]) Output: true Example 2 Input: @list = ([1, 4], [3, 4], [10, 4]) Output: true Example 3 Input: @list = ([0, 0], [1, 1], [2, 3]) Output: false Example 4 Input: @list = ([1, 1], [1, 1], [1, 1]) Output: true Example 5 Input: @list = ([1000000, 1000000], [2000000, 2000000], [3000000, 3000000]) Output: true I'll consider points A, B, C to be collinear if...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #332 (“Binary Date” and “Odd Letters”)

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-07-28 through 2025-08-03 is #332 The tasks for challenge #332 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 332-1: Binary Date Submitted by: Mohammad Sajid Anwar You are given a date in the format YYYY-MM-DD. Write a script to convert it into binary date. Example #1: Input: $date = "2025-07-26" Output: "11111101001-111-11010" Example #2: Input: $date = "2000-02-02" Output: "11111010000-10-10" Example #3: Input: $date = "2024-12-31" Output: "11111101000-1100-11111" To solve this, I'll make two subroutines: "dec2bin" which converts positive integers expressed as strings of decimal digits into strings of binary digits, and "d...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #331 (“Last Word” and “Buddy Strings”)

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-07-21 through 2025-07-27 is #331 The tasks for challenge #331 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 331-1: Last Word Submitted by: Mohammad Sajid Anwar You are given a string. Write a script to find the length of last word in the given string. Example #1: Input: $str = "The Weekly Challenge" Output: 9 Example #2: Input: $str = " Hello World " Output: 5 Example #3: Input: $str = "Let's begin the fun" Output: 3 There are a number of ways of approaching this, including using "split" to obtain a list of words which are in the string. But I'll use a simpler approach: I'll use an m// operator with a (capture group) to isolate the final word...