Posts

Showing posts from May, 2025

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #323 (“Increment Decrement” and “Tax Amount”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-05-26 through 2025-06-01 is #323 The tasks for challenge #323 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 323-1: Increment Decrement Submitted by: Mohammad Sajid Anwar You are given a list of operations. Write a script to return the final value after performing the given operations in order. The initial value is always 0. Possible Operations: ++x or x++: increment by 1 --x or x--: decrement by 1 Example #1: Input: @operations = ("--x", "x++", "x++") Output: 1 Operation "--x" => 0 - 1 => -1 Operation "x++" => -1 + 1 => 0 Operation "x++" => 0 + 1 => 1 Example #2: Input: @operations = ("x++", "++x", ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #322 (“String Format” and “Rank Array”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-05-19 through 2025-05-25 is #322 The tasks for challenge #322 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 322-1: String Format Submitted by: Mohammad Sajid Anwar You are given a string and a positive integer. Write a script to format the string, removing any dashes, in groups of size given by the integer. The first group can be smaller than the integer but should have at least one character. Groups should be separated by dashes. Example #1: Input: $str = "ABC-D-E-F", $i = 3 Output: "ABC-DEF" Example #2: Input: $str = "A-BC-D-E", $i = 2 Output: "A-BC-DE" Example #3: Input: $str = "-A-B-CD-E", $i = 4 Output: "A-BCDE" I first strip-out all t...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #321 (“Distinct Average” and “Backspace Compare”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of taks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-05-12 through 2025-05-18 is #321 The tasks for challenge #321 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 321-1: Distinct Average Submitted by: Mohammad Sajid Anwar You are given an array of numbers with even length. Write a script to return a count of distinct averages. The averages are calculated by removing the minimum and the maximum, then averaging the two. Example #1: Input: @nums = (1, 2, 4, 3, 5, 6) Output: 1 Step 1: Min = 1, Max = 6, Avg = 3.5 Step 2: Min = 2, Max = 5, Avg = 3.5 Step 3: Min = 3, Max = 4, Avg = 3.5 The count of distinct averages is 1. Example #2: Input: @nums = (0, 2, 4, 8, 3, 5) Output: 2 Step 1: Min = 0, Max = 8, Avg = 4 Step 2: Min = 2, Max = 5, Avg = 3.5 Step 3: Min = 3, Max...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #320 (“Maximum Count” and “Sum Difference”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of taks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-05-05 through 2025-05-11 is #320 The tasks for challenge #320 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 320-1: Maximum Count Submitted by: Mohammad Sajid Anwar You are given an array of integers. Write a script to return the maximum between the number of positive and negative integers. Zero is neither positive nor negative. Example #1: Input: @ints = (-3, -2, -1, 1, 2, 3) Output: 3 There are 3 positive integers. There are 3 negative integers. The maximum between 3 and 3 is 3. Example #2: Input: @ints = (-2, -1, 0, 0, 1) Output: 2 There are 1 positive integers. There are 2 negative integers. The maximum between 2 and 1 is 2. Example #3: Input: @ints = (1, 2, 3, 4) Output: 4 There are 4 positive intege...