Posts

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

Robbie Hatley's Solutions To The Weekly Challenge #286

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-08 through 2024-09-14 is #286. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 286-1: "Self Spammer" Submitted by: David Ferrone Write a program which outputs one word of its own script source code at random. A word is anything between whitespace, including symbols. Example 1: If the source code contains a line such as: 'open my $fh, "<", "ch-1.pl" or die;' then the program would output each of the words { open, my, $fh,, "<",, "ch-1.pl", or, die; } (along with other words in the source) with some positive probability. Example 2: Technically 'print(" hello ");' is *not* an example program, because it does not assign positive proba

Robbie Hatley's Solutions To The Weekly Challenge #285

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-01 through 2024-09-07 is #285. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 285-1: "No Connection" Submitted by: Mohammad Sajid Anwar You are given a list of routes, @routes. Write a script to find the destination with no further outgoing connection. Example 1: Input: @routes = (["B","C"], ["D","B"], ["C","A"]) Output: "A" "D" -> "B" -> "C" -> "A". "B" -> "C" -> "A". "C" -> "A". "A". Example 2: Input: @routes = (["A","Z"]) Output: "Z" This is just a matter of checking for end destina

Robbie Hatley's Solutions To The Weekly Challenge #284

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-08-25 through 2024-08-30 is #284. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 284-1: Lucky Integer Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script to find the lucky integer if found otherwise return -1. If there are more than one then return the largest. A lucky integer is an integer that has a frequency in the array equal to its value. Abundance, pushing, and popping are involved: Robbie Hatley's Perl Solution to The Weekly Challenge 284-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 284-2: Relative Sort Submitted by: Mohammad Sajid Anwar You are given two list of integers, @list1 and @list2. The elements in the @list

Robbie Hatley's Solutions To The Weekly Challenge #283

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-08-18 through 2024-08-24 is #283. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 283-1: Unique Number Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints, where every element appears more than once except one element. Write a script to find the one element that appears exactly one time. Example 1: Input: @ints = (3, 3, 1) Output: 1 Example 2: Input: @ints = (3, 2, 4, 2, 4) Output: 3 Example 3: Input: @ints = (1) Output: 1 Example 4: Input: @ints = (4, 3, 1, 1, 1, 4) Output: 3 I use the function "singleton" from CPAN module "List::SomeUtils" to find any singleton elements in the given array. foreach my $aref (@arrays) { say ''; my @singles =