Posts

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #293 ("Dominos" and "Boomerangs")

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-10-27 through 2024-11-02 is #293. The tasks for challenge #293 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 293-1: Similar Dominos Submitted by: Mohammad Sajid Anwar You are given a list of dominos, @dominos. Write a script to return the number of dominoes that are "similar" to any other domino. $dominos[i] = [a, b] and $dominos[j] = [c, d] are "similar" if either (a = c and b = d) or (a = d and b = c). Example 1: Input: @dominos = ([1, 3], [3, 1], [2, 4], [6, 8]) Similar Dominos are $dominos[0], $dominos[1], so output is 2. Example 2: Input: @dominos = ([1, 2], [2, 1], [1, 1], [1, 2], [2, 2]) Similar Dominos are $dominos[0], $dominos[1], $dominos[3], so output is 3. This is just a matter of follo

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #292 ("Twice Largest" and "Zuma Game")

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-10-20 through 2024-10-26 is #292. The tasks for challenge #292 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 292-1: "Twice Largest" Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints, where the largest integer is unique. Write a script to find whether the largest element in the array is at least twice as big as every other element in the array. If it is, return the index of the largest element; else return -1. Example 1: Input: (2, 4, 1, 0) The largest integer is 4 (with index 1), and it as at-least twice as large as every other element, so return its index, 1. Example 2: Input: (1, 2, 3, 4) The largest integer is 4, but it's less than twice as large as the nex

Robbie Hatley's Solutions To The Weekly Challenge #291 (Middle Index and Poker)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-10-13 through 2024-10-19 is #291. The tasks for challenge #291 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 291-1: "Middle Index" Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script to find the leftmost middle index (MI) i.e. the smallest amongst all the possible ones. A "middle index" is an index where ints[0] + ints[1] + ... + ints[MI-1] == ints[MI+1] + ints[MI+2] + ... + ints[ints.length-1]. If MI == 0, the left side sum is considered to be 0. Similarly, if MI == ints.length - 1, the right side sum is considered to be 0. Return the leftmost MI that satisfies the condition, or -1 if there is no such index. Example 1: Input: @ints = (2, 3, -1, 8, 4)

Robbie Hatley's Solutions To The Weekly Challenge #290 (With A Touch Of Macbeth)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-10-06 through 2024-10-12 is #290. Because these tasks both involve doubling things, my theme for this week is the witches' song from William Shakespeare's play Macbeth, Act IV, scene 1: Double, double toil and trouble; Fire burn and caldron bubble. Fillet of a fenny snake, In the caldron boil and bake; Eye of newt and toe of frog, Wool of bat and tongue of dog, Adder's fork and blind-worm's sting, Lizard's leg and howlet's wing, For a charm of powerful trouble, Like a hell-broth boil and bubble. The tasks for challenge #290 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 290-1: "Double Exists" Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script

Robbie Hatley's Solutions To The Weekly Challenge #289

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-09-29 through 2024-10-05 is #289. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 289-1: "Third Maximum" Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script to find the third distinct maximum in the given array. If third maximum doesn’t exist then return the maximum number. Example 1: Input: @ints = (5, 6, 4, 1) Output: 4 The first distinct maximum is 6. The second distinct maximum is 5. The third distinct maximum is 4. Example 2: Input: @ints = (4, 5) Output: 5 In the given array, the third maximum doesn't exist, therefore return the maximum. Example 3: Input: @ints = (1, 2, 2, 3) Output: 1 The first distinct maximum is 3. The second distinct maximum is 2. T

Robbie Hatley's Solutions To The Weekly Challenge #288

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-09-22 through 2024-09-28 is #288. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 288-1: "Closest Palindrome" Submitted by: Mohammad Sajid Anwar You are given a string, $str, which is a non-negative integer. Write a script to find out the closest palindrome, not including itself. If there are more than one then return the smallest. The closest is defined as the absolute difference minimized between two integers. Example 1: Input: $str = "123" Output: "121" Example 2: Input: $str = "2" Output: "1" (There are two closest palindrome "1" and "3". Therefore we return the smallest "1".) Example 3: Input: $str = "1400" Out

Robbie Hatley's Solutions To The Weekly Challenge #287

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-09-15 through 2024-09-21 is #287. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 287-1: "Strong Password" Submitted by: Mohammad Sajid Anwar You are given a string, $str. Write a program to return the minimum number of steps required to make the given string a "strong password". If the string is already a "strong password", then return 0. The definition of "strong password" is as follows: - It must have at least 6 characters. - It must contain at least one lowercase letter - It must contain at least one uppercase letter - It must contain at least one digit - It mustn't contain 3 repeating characters in a row Each of the following is considered one "step": - Ins