Posts

Showing posts from June, 2023

Robbie Hatley's Solutions To The Weekly Challenge #222

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-06-18 through 2023-06-24) is weekly challenge #222. Task 1 is as follows: "You are given a list of positive integers, @ints. Write a script to find the total matching members after sorting the list increasing order." The word "matching" is a tad vague in that context, but from the first example we can see that it means "the two arrays have the same element at the same index": Example 1: Original list: (1, 1, 4, 2, 1, 2) Sorted list : (1, 1, 1, 2, 3, 4) Comparing the two lists, we found 3 matching members: Index 0, Value 1 Index 1, Value 1 Index 3, Value 2 My solution is to compare the sorted and unsorted versions of each array using a 3-part loop and counting matching elements, like so: Robbie Hatley's Solution to The Weekly Challenge 22

Robbie Hatley's Solutions To The Weekly Challenge #221

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-06-11 through 2023-06-17) is weekly challenge #221. Task 1 is as follows: "You are given a list of strings "@words" and a string "$chars". A string is "good" if it contains only characters from "$chars", with each character used once-only per string. Write a script to return the sum of lengths of all elements of "@words" which are "good"." Example 1: Input: @strings = ("cat", "bt", "hat", "tree"), $chars = "atach" Output: 6 (The good strings that can be formed are "cat" and "hat", so the answer is 3 + 3 = 6.) Example 2: Input: @strings = ("hello", "world", "challenge"); $chars = "welldonehopper"; Out

Robbie Hatley's Solutions To The Weekly Challenge #220

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-06-04 through 2023-06-10) is weekly challenge #220. Task 1 is as follows: "You are given a list of words. Write a script to return the list of common characters (sorted alphabetically) found in every word of the given list." Now, that may sound simple, but that simplicity is partially derailed by the given examples: Example 1: Input = ("Perl", "Rust", "Raku") Output = ("r") Example 2: Input = ("love", "live", "leave") Output = ("e", "l", "v") Do you see the problem? Right, the letter comparisons -- at least in the case of English-Language letters -- are being done case-insensitively. My approach was to do the following for each array: Make a case-fold of a

Robbie Hatley's Solutions To The Weekly Challenge #219

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-28 through 2023-06-03) is weekly challenge #219. Task 1 is as follows: "Given a list of numbers, write a script to square each number in the list and return the sorted list of squares in increasing order." This is literally just a 1-liner: "my @squares = sort {$a<=>$b} map {$_*$_} @$aref;". My finished program looks like this: Robbie Hatley's Solution to The Weekly Challenge 219-1 Task 2 is as follows: You are given two list, @costs and @days. The list @costs contains the cost of three different types of travel cards you can buy. For example @costs = (5, 30, 90) Index 0 element represent the cost of 1 day travel card. Index 1 element represent the cost of 7 days travel card. Index 2 element represent the cost of 30 days travel card. Th