Recursive Binary Description
Recently, I made my very first contribution to OEIS by extending and adding a b-file to sequence A049064. The sequence starts with 0
, and then the next values are derived from giving a "binary description" of the last item.
For example, the second term would be 10
, because there was one 0
in the first element. The third term would be 1110
, because there was one 1
and one 0
. The fourth would be 11110
. because there are three (11
in binary!) 1
s and one 0
. Below is a breakdown of the fifth term to make this process clear:
> 11110
> 1111 0 (split into groups of each number)
> 4*1 1*0 (get count of each number in each group)
> 100*1 1*0 (convert counts to binary)
> 100110 (join each group back together)
And here's an example for going from the 6th to the 7th term:
> 1110010110
> 111 00 1 0 11 0
> 3*1 2*0 1*1 1*0 2*1 1*0
> 11*1 10*0 1*1 1*0 10*1 1*0
> 111100111010110
You can check out a reference programφ I made to calculate the terms.
Your Job
You need to create a program or function which takes in a number n
via standard input or function arguments, and prints out the sequence from the 1st
term to the (n+1)th
term, separated by a newline. If you would like a look at the lower numbers, you may refer to the b-file from the OEIS page. However, your program/function should support 0 <= n <= 30
, i.e. up to the 31st term. This is no small feat, as A049064(30)
is over 140,000 digits longδ. If you would like to see what the 31st term should be, I've put it on Pastebin.
Example I/O
func(10)
0
10
1110
11110
100110
1110010110
111100111010110
100110011110111010110
1110010110010011011110111010110
1111001110101100111001011010011011110111010110
1001100111101110101100111100111010110111001011010011011110111010110
func(0)
0
func(3)
0
10
1110
11110
There is only one rule: No standard loopholes!
This is code-golf, so the lowest byte count wins.
φ - Gist can be found here, and an ideone demo is here.
δ - Just in case you were wondering, my estimates at the length of the 100th term put it at approximately 3.28x10250 characters long, which would be quite a lot for anyone to calculate.
[0]\n[1, 0]\n[1, 1, 1, 0]\n...
\$\endgroup\$