15
1
You will be given a number x, where 0 <= x <= 2^32 - 1.
You should output a list of numbers in decimal, after recursive splitting in binary format.
Examples:
Example 1:
255 -> 255 15 15 3 3 3 3 1 1 1 1 1 1 1 1
The current list is just 255.
The binary representation of 255 is 1111 1111. Splitting it, we get 1111 and 1111, which in decimal are 15 and 15.
We add those to the list, so we will have 255 15 15.
Now the numbers 15 and 15 will serve as inputs and these numbers are to be split.
Doing it again, we get (3 3 from both 15s): 255 15 15 3 3 3 3.
Continuing the logic, final list will be 255 15 15 3 3 3 3 1 1 1 1 1 1 1 1. And since 1 can no longer be split, the output stops.
Example 2:
225 -> 225 14 1 3 2 1 1 1 0
The starting list is 225.
The binary representation of 225 is 1110 0001. Splitting it, we get 1110 and 0001, which in decimal are 14 and 1.
Adding those to the list, we get 225 14 1.
Now the numbers 14 and 1 will serve as inputs and these numbers are to be split.
Since 1 is no splittable, the output will be 225 14 1 3 2.
Example 3:
32 -> 32 4 0 1 0
Conditions:
- If the number of binary digits are odd, the first number will have one fewer binary digit than the next one. Example,
20 (10100)will be split as10and100, with decimal output being2and4. - Standard loophole rules apply.
0s and1s do not propagate further.- Program crashing for trying to display too many numbers is a valid exit condition.
Just a suggestion but what about having the binary digits padded with
0s when the length is odd? – caird coinheringaahing – 2017-05-19T06:12:55.9231@Satan'sSon If you pad in front, that's equivalent to the description. – isaacg – 2017-05-19T06:13:22.417
1Is the specified output order required or just the values? – Jonathan Allan – 2017-05-19T06:17:04.590
@Satan'sSon No padding with
0s. – ctrl-shift-esc – 2017-05-19T06:28:05.4471@JonathanAllan The specified output order is required. – ctrl-shift-esc – 2017-05-19T06:28:36.303
Suggesting different title of "Split this in Half". – Magic Octopus Urn – 2017-05-19T17:02:53.577