Posts

Showing posts from March, 2024

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