Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #384 (“Base N” and “Special Binary Substrings”)

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-07-27 through 2026-08-02 is #384.

The tasks for challenge #384 are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 384-1: Base N
Submitted by: Mohammad Sajid Anwar
You are given a number and a base integer. Write a script
to convert the given number in the given base integer.

To solve this problem, I use the excellent base conversion routines provided by "Math::BigInt", augmented by Gnu's "GMP" library, which will provide both blazing speed and unlimited precision. (I usually "roll my own" in these challenges, but not this time; it would be an insult to the hard-working authors of "Math::BigInt" and "GMP" for me to NOT use their products in a case where they're so clearly called for.)

Robbie Hatley's Perl Solution to The Weekly Challenge 384-1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 384-2: Special Binary Substrings
Submitted by: Mohammad Sajid Anwar
You are given a binary string. Write a script to return all
non-empty substrings (distinct) that have the same number of
0’s and 1’s, and all the 0’s and all the 1’s in these substrings
are grouped consecutively.

To solve this problem, I use a pair of nested 3-part "for" loops to examine every even-length substring of each input string, and return only the unique "Special Binary Substrings" as described in the problem description.

Robbie Hatley's Perl Solution to The Weekly Challenge 384-2

That's it for challenge 384; see you on challenge 385!

Comments

Popular posts from this blog

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #336 (“Equal Group” and “Final Score”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #341 (“Broken Keyboard” and “Reverse Prefix”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #339 (Theme: “Maximum Overdrive”)