Posts

Showing posts from June, 2025

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #325 (“Consecutive Ones” and “Final Price”)

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-06-09 through 2025-06-15 is #325 The tasks for challenge #325 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 325-1: Consecutive Ones Submitted by: Mohammad Sajid Anwar You are given a binary array containing only 0s or/and 1s. Write a script to find the maximum consecutive 1s in the given array. Example #1: Input: @binary = (0, 1, 1, 0, 1, 1, 1) Output: 3 Example #2: Input: @binary = (0, 0, 0, 0) Output: 0 Example #3: Input: @binary = (1, 0, 1, 0, 1, 1) Output: 2 To solve this problem, I'll make a sub that counts each cluster of 1s and keeps track of the max count seen. Robbie Hatley's Perl Solution to The Weekly Challenge 325-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #324 (“2D Array” and “Total XOR”)

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-06-02 through 2025-06-08 is #324 The tasks for challenge #324 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 324-1: 2D Array Submitted by: Mohammad Sajid Anwar You are given an array of integers and two integers $r amd $c. Write a script to create two dimension array having $r rows and $c columns using the given array. Example #1: Input: @ints = (1, 2, 3, 4), $r = 2, $c = 2 Output: ([1, 2], [3, 4]) Example #2: Input: @ints = (1, 2, 3), $r = 1, $c = 3 Output: ([1, 2, 3]) Example #3: Input: @ints = (1, 2, 3, 4), $r = 4, $c = 1 Output: ([1], [2], [3], [4]) To reshape a 1D array into a 2D array using same contents, one should really use APL, in which case the entire program would only be a few characters...