Posts

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

Robbie Hatley's Solutions To The Weekly Challenge #276

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-06-30 through 2024-07-06 is #276. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 276-1: Complete Day Submitted by: Mohammad Sajid Anwar Given an array of integers, write a script to return the number of pairs that forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24 hours. Example 1 input: [12, 12, 30, 24, 24], Expected output: 2 Pair 1: (12, 12) Pair 2: (24, 24) Example 2 input: [72, 48, 24, 5], Expected output: 3 Pair 1: (72, 48) Pair 2: (72, 24) Pair 3: (48, 24) Example 3 input: [12, 18, 24], Expected output: 0 This is just a matter of using nested 3-part loops to avoid duplicating pairs, then seeing which pairs add up to an integer x such that 0 == x%24.

Robbie Hatley's Solutions To The Weekly Challenge #275

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-06-23 through 2024-06-29 is #275. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 275-1: Broken Keys Submitted by: Mohammad Sajid Anwar You are given a sentence $sentence and list of broken keys @keys. Write a script to find out how many words can be typed fully. Example 1: Input: $sentence = "Perl Weekly Challenge", @keys = ('l', 'a') Output: 0 Example 2: Input: $sentence = "Perl and Raku", @keys = ('a') Output: 1 Only Perl since the other word two words contain 'a' and can't be typed fully. Example 3: Input: $sentence = "Well done Team PWC", @keys = ('l', 'o') Output: 2 Example 4: Input: $sentence = "The joys of polyglottism&

Robbie Hatley's Solutions To The Weekly Challenge #274

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-06-16 through 2024-06-22 is #274. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 274-1: Goat Latin Submitted by: Mohammad Sajid Anwar You are given a sentence, $sentance. Write a script to convert $sentence to Goat Latin, a made up language similar to Pig Latin. Rules for Goat Latin: 1) If a word begins with a vowel ("a", "e", "i", "o", "u"), append "ma" to the end of the word. 2) If a word begins with consonant i.e. not a vowel, remove first letter and append it to the end then add "ma". 3) Add letter "a" to the end of first word in the sentence, "aa" to the second word, etc. Example 1: Input: $sentence = "I l

Robbie Hatley's Solutions To The Weekly Challenge #273

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-06-09 through 2024-06-15 is #273. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 273-1: Percentage of Character Submitted by: Mohammad Sajid Anwar You are given a string, $str and a character $chr. Write a script to return the nearest integer percentage of the characters in $str which are $chr. Example 1: Input: $str = "perl", $chr = "e" Output: 25 Example 2: Input: $str = "java", $chr = "a" Output: 50 Example 3: Input: $str = "python", $chr = "m" Output: 0 Example 4: Input: $str = "ada", $chr = "a" Output: 67 Example 5: Input: $str = "ballerina", $chr = "l" Output: 22 Example 6: Input: $str = "analitik&quo