Posts

Showing posts from July, 2024

Robbie Hatley's Solutions To The Weekly Challenge #280

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-07-28 through 2024-08-03 is #280. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 280-1: Twice Appearance Submitted by: Mohammad Sajid Anwar Given a string containing lowercase English letters only, write a script to print the first letter to appear a second time. [Note, Robbie Hatley, 2024-07-29: The original version said "first letter that appears twice", but the examples contradict that, so I edited it to read "a second time" instead of "twice", in order to jibe with the examples. For example, in "acbddbca" the first letter to appear twice is "a", but the first letter to appear a second time is "d". The difference is that "twice" is not positio

Robbie Hatley's Solutions To The Weekly Challenge #279

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-07-21 through 2024-07-27 is #279. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 279-1: Sort Letters Submitted by: Mohammad Sajid Anwar Given two arrays, @letters and @weights, write a script to sort @letters based on @weights. Example 1: Input: @letters = ('R', 'E', 'P', 'L') @weights = (3, 2, 1, 4) Output: PERL Example 2: Input: @letters = ('A', 'U', 'R', 'K') @weights = (2, 4, 1, 3) Output: RAKU Example 3: Input: @letters = ('O', 'H', 'Y', 'N', 'P', 'T') @weights = (5, 4, 2, 6, 1, 3) Output: PYTHON I use List::MoreUtils::Zip6 to make a list of [letter, weight] pairs, sort those

Robbie Hatley's Solutions To The Weekly Challenge #278

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-07-14 through 2024-07-20 is #278. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 278-1: Sort String Submitted by: Mohammad Sajid Anwar Given a shuffled string, write a script to return the sorted string. A string is shuffled by appending word position to each word. Example 1 input: "and2 Raku3 cousins5 Perl1 are4" Expected output: "Perl and Raku are cousins" Example 2 input: "guest6 Python1 most4 the3 popular5 is2 language7" Expected output: "Python is the most popular guest language" Example 3 input: "Challenge3 The1 Weekly2" Expected output: "The Weekly Challenge" My approach was to do this: Split the string by whitespace to array of tokens &quo

Robbie Hatley's Solutions To The Weekly Challenge #277

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-07-07 through 2024-07-13 is #277. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 277-1: Count Common Submitted by: Mohammad Sajid Anwar Given two arrays of strings,write a script to return the count of words which appear once-each in the two arrays. # Example 1 input: [ ["Perl", "is", "my", "friend"], ["Perl", "and", "Raku", "are", "friend"], ], # Expected output: 2 # (The words "Perl" and "friend" appear once in each array.) # Example 2 input: [ ["Perl", "and", "Python", "are", "very", "similar"], [&qu