Posts

Showing posts from January, 2025

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #304 ("Arrange Binary" and "Maximum Average")

Image
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-01-13 through 2025-01-19 is #304. The tasks for challenge #304 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 304-1: "Arrange Binary" Submitted by: Mohammad Sajid Anwar Reworded for clarity by Robbie Hatley. You are given a list @d of 0s and 1s and a positive integer $n. Write a script to return true if you can re-arrange the list by replacing at least $n "0" digits of @d with "1" in such a way that no two consecutive digits are 1, otherwise return false. Example #1: Input: @digits = (1, 0, 0, 0, 1), $n = 1 Output: true Re-arranged list: (1, 0, 1, 0, 1) Example #2: Input: @digits = (1, 0, 0, 0, 1), $n = 2 Output: false First of all, @d needs to be checked to see if it already has any conse...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #303 ("3-Digits Even" and "Delete and Earn")

Image
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-01-06 through 2025-01-12 is #303. The tasks for challenge #303 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 303-1: "3-Digits Even" Submitted by: Mohammad Sajid Anwar You are given a list (3 or more) of positive integers, @ints. Write a script to return all even 3-digits integers that can be formed using the integers in the given list. Example #1: Input: @ints = (2, 1, 3, 0) Output: (102, 120, 130, 132, 210, 230, 302, 310, 312, 320) Example #2: Input: @ints = (2, 2, 8, 8, 2) Output: (222, 228, 282, 288, 822, 828, 882) This looks like yet another job for my favorite CPAN module, "Math::Combinatorics". I'll first extract the digits from @ints and push them to an array "@digits", then I...