Menu

PWC 367 Overlapping Oddities
πŸ“°

PWC 367 Overlapping Oddities

DEV CommunityΒ·Bob LiedΒ·6 months ago
#JPor7Im2
#perl#perlweeklychallenge#pwc#software#coding
Reading 0:00
15s threshold

Task 1, Maximum Odd Binary

It's the week of the Artemis 2 mission to the moon, and we have a problem about odd numbers. I'd call that a Space Oddity .

Task Description

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.

Example 1: Input: $str = "1011" , Output: "1101"

Example 2: Input: $str = "100" , Output: "001"

Example 3: Input: $str = "111000" , Output: "110001"

Example 4: Input: $str = "0101" , Output: "1001"

Example 5: Input: $str = "1111" , Output: "1111"

Task Cogitation

To be as large as possible, a binary number must have all its 1s in the most-significant bits. To be odd, the least significant bit must be a one.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.