Posts

Showing posts from August, 2024

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

Robbie Hatley's Solutions To The Weekly Challenge #282

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-11 through 2024-08-17 is #282. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 282-1: Good Integer Submitted by: Mohammad Sajid Anwar Write a script which, given a positive integer x with 3 or more digits, returns the Good Integers within x (or -1 if none found), where a "Good Integer" is a substring of x consisting of exactly 3 identical digits (greedy match, left and right). For example, in "2899467772", "777" is a "Good Integer"; but in "28994677772", the string "777" is NOT a "Good Integer", even though it appears in two places, because the substring of 7s is 4 digits long, not 3 digits. Example 1: Input: $int = 12344456 Output: "444...

Robbie Hatley's Solutions To The Weekly Challenge #281

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-04 through 2024-08-10 is #281. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 281-1: Check Color Submitted by: Mohammad S Anwar Write a script which, given the coordinates of a square on a chessboard in algebraic notation, prints "true" if the square is white, "false" if the square is black. Example 1: Input: 'd3' Output: 'true' Example 2: Input: 'g5' Output: 'false' Example 3: Input: 'e6' Output: 'true' The is just a matter of calculating the parity of the sum of horizontal and vertical distances relative to square a1 (black). If the combined parity is 0, the output is 0/black/false. If the combined parity is 1, the output is 1/white/true. ...