Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #332 (“Binary Date” and “Odd Letters”)
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 for the week of 2025-07-28 through 2025-08-04 is #332
The tasks for challenge #332 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 332-1: Binary Date Submitted by: Mohammad Sajid Anwar You are given a date in the format YYYY-MM-DD. Write a script to convert it into binary date. Example #1: Input: $date = "2025-07-26" Output: "11111101001-111-11010" Example #2: Input: $date = "2000-02-02" Output: "11111010000-10-10" Example #3: Input: $date = "2024-12-31" Output: "11111101000-1100-11111"
To solve this, I'll make two subroutines: "dec2bin" which converts positive integers expressed as strings of decimal digits into strings of binary digits, and "date2bin" which changes all clusters of digits in a string to their binary equivalents by calling "dec2bin" in "s/(\d+)/dec2bin($1)/egr".

Robbie Hatley's Perl Solution to The Weekly Challenge 332-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 332-2: Odd Letters Submitted by: Mohammad Sajid Anwar You are given a string. Write a script to find out if each letter in the given string appeared odd number of times. Example #1: Input: "weekly" Output: false Example #2: Input: "Perl" Output: true Example #3: Input: "challenge" Output: false
I'll use a hash to keep track of the number of times each letter appears, then I'll use the "none" function from CPAN module "List::Util" to determine if none of the keys of the hash have even values.

Robbie Hatley's Perl Solution to The Weekly Challenge 332-2
That's it for challenge 332; see you on challenge 333!
Comments
Post a Comment