Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #387 (“Rearrange Binary String” and “Atoms Count”)
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-17 through 2026-08-23 is #387. The tasks for challenge #387 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 387-1: Rearrange Binary String Submitted by: Mohammad Sajid Anwar You are given a binary string. Write a script to re-arrange the string that all occurrences of “01” are simultaneously replaced with “10” until no occurrences of “01” exist. Return the total steps needed. I'll use a s///g operator in a while loop and count how many times it runs. Robbie Hatley's Perl Solution to The Weekly Challenge 387-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 387-2: Atoms Count Submitted by: Mohammad Sajid Anwar You are given a chemical formula with element...