Posts

Showing posts from June, 2024

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

Robbie Hatley's Solutions To The Weekly Challenge #272

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-02 through 2024-06-08 is #272. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 272-1: Defang IP Address Submitted by: Mohammad Sajid Anwar You are given a valid IPv4 address. Write a script to return the defanged version of the given IP address. A "defanged" IP address replaces every period “.” with “[.]". Example 1: Input: $ip = "1.1.1.1" Output: "1[.]1[.]1[.]1" Example 2: Input: $ip = "255.101.1.0" Output: "255[.]101[.]1[.]0" The "s" operator makes quick work of this: sub defang ($x) {$x =~ s/\./[.]/gr} Robbie Hatley's Perl Solution to The Weekly Challenge 272-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...