Menu

πŸ“°
0

PWC 367 Overlapping Oddities

DEV Community: perlΒ·Bob LiedΒ·about 1 month ago
#JPor7Im2
#dev#task1#how#task2#class#code
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. So, what has to happen is that all the 1s shift to the left, one shifts to the right, and all the zeroes form a space between them.…

Continue reading β€” create a free account

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

Read More