Weekly Challenge: Maximum conflict
Weekly Challenge 367 Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and ...

Source: DEV Community
Weekly Challenge 367 Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge, My solutions Task 1: Max Odd Binary Task You are given a binary string that has at least one 1. Write a script to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number and return the resulting binary string. The resulting string can have leading zeros. My solution This task requires some number theory to implement the solution. To make an odd binary number the last bit (less significant) needs to be a 1. To make the largest possible number, the remaining set bits need to be the largest (left / most significant) bits. The parts of this task are: Use a regular expres