Posts

Showing posts from May, 2023

Robbie Hatley's Solutions To The Weekly Challenge #218

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here: The Weekly Challenge This week (2023-05-21 through 2023-05-27) is weekly challenge #218. Task 1 is as follows: "Given a list of 3 or more integers, write a script to find the 3 integers whose product is maximum and return their product." This is just a matter of trying all combinations and seeing which is max. I use the "Math::Combinatorics" CPAN module again (it's becoming one of my favorite go-to modules): Robbie Hatley's Solution to The Weekly Challenge 218-1 Task 2 is as follows: "You are given a m x n binary matrix i.e. having only 1 and 0. You are allowed to make as many moves as you want to get the highest score. A move can be either toggling each value in a row or column. To get the score, convert the each row binary to dec and return the sum." Yikes. There is

Robbie Hatley's Solutions To The Weekly Challenge #217

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here: The Weekly Challenge This week (2023-05-14 through 2023-05-20) is weekly challenge #217. Task 1 is as follows: "Given an n x n matrix of real numbers (where n >= 2), write a script to find 3rd smallest element in the sorted matrix." This is pretty simple. To get the 3rd-smallest member of a matrix, just dump the rows into an array, sort it, and print element 2: Robbie Hatley's Solution to The Weekly Challenge 217-1 Task 2 is as follows: "You are given a list of positive integers. Write a script to concatenate the integers to form the highest possible value." There are two basic ways I can see to approach this: Firstly, one could make a special sort algorithm which sorts the numbers in such a way that, when they're concatenated, one gets the greatest possible numerical value

Robbie Hatley's Solutions To The Weekly Challenge #216

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here: The Weekly Challenge This week (2023-05-07 through 2023-05-13) is weekly challenge #216. Task 1 is as follows: "You are given a list of words and a random registration number. Write a script to find all the words in the given list that has every letter in the given registration number." This is pretty simple. Just check each word to see if it contains all of the letters from the registration string, then output the subset of the original word set which contains those members which contain all registration letters. I use a ranged for loop to push "registered" words onto a "@regd_wrds" array: Robbie Hatley's Solution to The Weekly Challenge 216-1 Task 2 is as follows: "You are given a list of word stickers and a target word. Write a script to find out how many word sticke

Robbie Hatley's Solutions To The Weekly Challenge #215

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here: The Weekly Challenge This week (2023-04-30 through 2023-05-06) is weekly challenge #215. Task 1 is as follows: "You are given a list of words (alphabetic characters only) of same size. Write a script to remove all words not sorted alphabetically and print the number of words in the list that are not alphabetically sorted." I found the solution easy, just a matter of determining which words are "sorted" by comparing each $word to join(sort(split($word))), like so: Robbie Hatley's Perl Solution to The Weekly Challenge 215-1 Task 2 is as follows: "You are given a list of numbers having just 0 and 1. You are also given placement count (>=1). Write a script to find out if it is possible to replace 0 with 1 the given number of times in the given list. The only condition is that you

Robbie Hatley's Solutions To The Weekly Challenge #214

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here: The Weekly Challenge This week (2023-04-23 through 2023-04-29) is weekly challenge #214. Unfortunately, I ran out of time on this one, so this entry is just a stub. 215 will be complete, though. Task 1 is as follows: "Task description would have gone here." My comments would have gone here. My solution would have been: Robbie Hatley's Perl Solution to The Weekly Challenge 213-1 Task 2 is as follows: "Task description would have gone here." My comments would have gone here. My solution would have been: Robbie Hatley's Perl Solution to The Weekly Challenge 212-2 Well that was a bloody disaster. :-( But I'll see you on 215! :-)