This was inspired by Problem 13 - Non-Repeating Binary of HP CodeWars' recent competition.
Let's take a random decimal number, say
727429805944311
and look at its binary representation:
10100101011001011111110011001011101010110111110111
Now split that binary representation into subsequences where the digits 0
and 1
alternate.
1010 010101 10 0101 1 1 1 1 1 10 01 10 0101 1 1010101 101 1 1 1 101 1 1
And convert each subsequence back into decimal.
10 21 2 5 1 1 1 1 1 2 1 2 5 1 85 5 1 1 1 5 1 1
The Task
Take a single, positive integer as input and output the sequence of positive integers obtained by the above process.
Details
- Input and output must be in decimal or unary.
- Numbers in the output must be separated in a sensible, human-readable fashion, and they must be in decimal or unary. No restriction on white space. Valid output styles:
[1,2,3]
,1 2 3
,1\n2\n3
where\n
are literal newlines, etc.
Test cases
Input | Output
0 | 0
1 | 1
2 | 2
3 | 1 1
4 | 2 0
5 | 5
6 | 1 2
7 | 1 1 1
8 | 2 0 0
9 | 2 1
10 | 10
50 | 1 2 2
100 | 1 2 2 0
1000 | 1 1 1 1 10 0 0
10000 | 2 1 1 2 0 2 0 0 0
12914 | 1 2 2 1 1 2 2
371017 | 5 42 10 2 1
Additional note: all numbers in the output should be of the form (2^k-1)/3
or 2*(2^k-1)/3
. That is, 0 1 2 5 10 21, 42, 85, 170, ...
, which is A000975 in the OEIS.
|tac
will remain in my answer then :) \$\endgroup\$