39
7
Consider the following process:
Take some non-negative integer N.
e.g. N =
571Express it in binary with no leading zeroes. (Zero itself is the only exception, becoming
0.)e.g.
571=1000111011in binaryBreak apart consecutive runs of ones and zeroes in this binary representation.
e.g.
1000111011→1,000,111,0,11Sort the runs from longest to shortest.
e.g.
1,000,111,0,11→000,111,11,1,0Overwrite all the digits in each run with alternating
1's and0's, always starting with1's.e.g.
000,111,11,1,0→111,000,11,0,1Concatenate the result to get a new binary number.
e.g.
111,000,11,0,1→1110001101=909in decimal
When you plot the values produced by this process you get a pretty neat graph:
And it's hopefully apparent why I'm calling the resulting sequence the Temple Skyline sequence:
Challenge
Write a program or function that takes in a non-negative integer N and prints or returns the corresponding Temple Skyline sequence number. Your input and output should both be in decimal.
e.g. If the input is 571 the output should be 909.
The shortest code in bytes wins.
For reference, here are the terms in the sequence from N = 0 to 20:
0 1
1 1
2 2
3 3
4 6
5 5
6 6
7 7
8 14
9 13
10 10
11 13
12 12
13 13
14 14
15 15
16 30
17 29
18 26
19 25
20 26


You can use
.BQinstead ofjQ2, which means you can lose the space between the8and the preceding2. – Sok – 2015-10-06T09:01:10.233is*R\s=!Z_ShMr.BQ8 2` is an interesting same-length solution. Mostly posting because I didn't really expect the assign in a map argument to work. – FryAmTheEggman – 2015-10-06T15:17:27.5271@FryAmTheEggman Replace
\swith]`. Saves one byte. – Jakube – 2015-10-11T15:38:43.197