Posts

Showing posts from March, 2025

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #312 ("Minimum Time" and "Balls and Boxes")

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 2025-03-10 through 2025-03-16 is #312. The tasks for challenge #312 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 312-1: Minimum Time Submitted by: Mohammad Sajid Anwar You are given a typewriter with lowercase english letters a to z arranged in a circle. Typing a character takes 1 second. Moving the pointer one character clockwise or anti-clockwise also takes 1 second. The pointer initially points to a. Write a script to return minimum time it takes to print a given string. Example #1: Input: $str = "abc" Output: 5 The pointer is at 'a' initially. 1 sec - type the letter 'a' 1 sec - move pointer clockwise to 'b' 1 sec - type the letter 'b' 1 sec - move pointer clockwise to 'c...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #311 ("Upper Lower" and "Group Digit Sum")

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 2025-03-03 through 2025-03-09 is #311. The tasks for challenge #311 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 311-1: Upper Lower Submitted by: Mohammad Sajid Anwar You are given a string consisting of english letters only. Write a script to convert lower case to upper and upper case to lower in the given string. Example #1: Input: $str = "pERl" Output: "PerL" Example #2: Input: $str = "rakU" Output: "RAKu" Example #3: Input: $str = "PyThOn" Output: "pYtHoN" This can be easily done with a one-liner using Perl's "transpose" operator, "tr", aka "y": y/[a-zA-Z]/[A-Za-z]/,print while <> Robbie Hatley's Pe...