Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #386 (“Reverse Base” and “Rational Numbers”)
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 2026-08-10 through 2026-08-16 is #386.
The tasks for challenge #386 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 386-1: Reverse Base Submitted by: Mohammad Sajid Anwar You are given a string representing a number, and an integer specifying the base of that representation. Write a function to convert this string to an integer. (For bases greater than 10, use characters A-Z, a-z, + and / in that order.)
This is basically a repeat of 384, so I'll just re-use that solution, which uses the base conversion routines in Math::BigInt. Though, I'll have to make some minor tweaks to allow for the collation sequence specified in 386.
Robbie Hatley's Perl Solution to The Weekly Challenge 386-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 386-2: Rational Numbers Submitted by: Mohammad Sajid Anwar You are given two strings representing non-negative rational numbers. Write a script to return true if the two given rational numbers are same, otherwise false.
Rather than use inexact approximations (which was my first inclination), I chose to build "Math::BigRat" objects for each of the input strings, then simply compare them.
Robbie Hatley's Perl Solution to The Weekly Challenge 386-2
That's it for challenge 386; see you on challenge 387!
Comments
Post a Comment