Posts

Robbie Hatley's Solutions To The Weekly Challenge #265

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 This week (2024-04-14 through 2024-04-20) is weekly challenge #265. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 265-1: 33% Appearance Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script to find an integer in the given array that appeared 33% or more. If more than one found, return the smallest. If none found, then return undef. Example 1: Input: @ints = (1,2,3,3,3,3,4,2) Output: 3 1 appeared 1 times. 2 appeared 2 times. 3 appeared 4 times. 3 appeared 50% (>33%) in the given array. Example 2: Input: @ints = (1,1) Output: 1 1 appeared 2 times. 1 appeared 100% (>33%) in the given array. Example 3: Input: @ints = (1,2,3) Output: 1 1 appeared 1 times. 2 appeared 1 times. 3 appeared 1 times. Since all three app

Robbie Hatley's Solutions To The Weekly Challenge #264

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 This week (2024-04-07 through 2024-04-13) is weekly challenge #264. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 264-1: Greatest English Letter Submitted by: Mohammad Sajid Anwar You are given a string, $str, made up of only alphabetic characters [a..zA..Z]. Write a script to return the greatest english letter in the given string. (A letter is "greatest" if it occurs as lower and upper case. Also letter ‘b’ is greater than ‘a’ if ‘b’ appears after ‘a’ in the English alphabet. Example 1: Input: $str = 'PeRlwEeKLy' Output: L There are two letters E and L that appears as lower and upper. The letter L appears after E, so the L is the greatest english letter. Example 2: Input: $str = 'ChaLlenge' Output: L Example 3: Input: $str = &

Robbie Hatley's Solutions To The Weekly Challenge #263

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 This week (2024-03-31 through 2024-04-06) is weekly challenge #263. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 263-1: Target Index Submitted by: Mohammad Sajid Anwar You are given an array of integers @ints and a target element $k. Write a script to return the list of indices in the sorted array where the element is same as the given target element. Example 1: Input: @ints = (1, 5, 3, 2, 4, 2), $k = 2 Output: (1, 2) Sorted array: (1, 2, 2, 3, 4, 5) Target indices: (1, 2) as $ints[1] = 2 and $ints[2] = 2 Example 2: Input: @ints = (1, 2, 4, 3, 5), $k = 6 Output: () No element in the given array matching the given target. Example 3: Input: @ints = (5, 3, 2, 4, 2, 1), $k = 4 Output: (4) Sorted array: (1, 2, 2, 3, 4, 5) Target index: (4) as $ints[4] = 4

Robbie Hatley's Solutions To The Weekly Challenge #262

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 This week (2024-03-247 through 2024-03-30) is weekly challenge #262. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 262-1: Max Positive Negative Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script to return the maximum number of either positive or negative integers in the given array. Example 1: Input: @ints = (-3, 1, 2, -1, 3, -2, 4) Output: 4 Count of positive integers: 4 Count of negative integers: 3 Maximum of count of positive and negative integers: 4 Example 2: Input: @ints = (-1, -2, -3, 1) Output: 3 Count of positive integers: 1 Count of negative integers: 3 Maximum of count of positive and negative integers: 3 Example 3: Input: @ints = (1,2) Output: 2 Count of positive integers: 2 Count of negative intege

Robbie Hatley's Solutions To The Weekly Challenge #261

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 This week (2024-03-17 through 2024-03-23) is weekly challenge #261. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 261-1: Element Digit Sum Submitted by Mohammad Sajid Anwar Reworded for clarity by Robbie Hatley. You are given an array of integers, @ints. Write a script to evaluate the absolute value of the difference between the element and digit sums of @ints. Example 1: Input: @ints = (1,2,3,45) Output: 36 Element Sum: 1 + 2 + 3 + 45 = 51 Digit Sum: 1 + 2 + 3 + 4 + 5 = 15 Absolute Difference: |51 - 15| = 36 Example 2: Input: @ints = (1,12,3) Output: 9 Element Sum: 1 + 12 + 3 = 16 Digit Sum: 1 + 1 + 2 + 3 = 7 Absolute Difference: |16 - 7| = 9 Example 3: Input: @ints = (1,2,3,4) Output: 0 Element Sum: 1 + 2 + 3 + 4 = 10 Digit Sum: 1 + 2 + 3 + 4 = 10 Abs

Robbie Hatley's Solutions To The Weekly Challenge #260

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 This week (2024-03-10 through 2024-03-16) is weekly challenge #260. Its tasks are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 260-1: Unique Occurrences Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints. Write a script to return 1 if the number of occurrences of each value in the given array is unique or 0 otherwise. Example 1: Input: @ints = (1,2,2,1,1,3) Output: 1 The number 1 occurred 3 times. The number 2 occurred 2 times. The number 3 occurred 1 time. All occurrences are unique, therefore the output is 1. Example 2 Input: @ints = (1,2,3) Output: 0 Example 3 Input: @ints = (-2,0,1,-2,1,1,0,1,-2,9) Output: 1 There are probably other ways to solve this (TIMTOWTDI), but the method I stumbled on was to first create a sub called "occ

Robbie Hatley's Solutions To The Weekly Challenge #258

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 This week (2024-02-25 through 2024-03-02) is weekly challenge #258. Its tasks are as follows: Task 258-1: Count Even Digits Number Submitted by: Mohammad Sajid Anwar You are given a array of positive integers, @ints. Write a script to find out how many integers have even number of digits. Example 1: Input: @ints = (10, 1, 111, 24, 1000) Output: 3 There are 3 integers having even digits i.e. 10, 24 and 1000. Example 2: Input: @ints = (111, 1, 11111) Output: 0 Example 3: Input: @ints = (2, 8, 1024, 256) Output: 1 I'm "traveling light" this week, so my solutions for 258-1 and 258-2 are about 50 times shorter than the programs I normally write for The Weekly Challenge. My solution for 258-1 is especially short; it uses "grep" to filter @ARGV for numbers with an even number of digi