%I #14 Mar 12 2022 01:34:44
%S 1,11,2,12,111,21,3,13,121,1111,112,22,211,31,4,14,131,1211,122,1112,
%T 11111,1121,113,23,221,2111,212,32,311,41,5,15,141,1311,132,1212,
%U 12111,1221,123,1113
%N Take the binary expansion of n, starting with the most significant bit, and concatenate the lengths of the runs.
%C Obviously this compressed notation is useful only for n < 1023. A101211 is a version which works for all n.
%H Rémy Sigrist, <a href="/A318927/b318927.txt">Table of n, a(n) for n = 1..1022</a>
%e n, binary, run lengths, -> a(n)
%e 1, [1], [1] -> 1
%e 2, [1, 0], [1, 1] -> 11
%e 3, [1, 1], [2] -> 2
%e 4, [1, 0, 0], [1, 2] -> 12
%e 5, [1, 0, 1], [1, 1, 1] -> 111
%e 6, [1, 1, 0], [2, 1] -> 21
%e 7, [1, 1, 1], [3] -> 3
%e ...
%t Array[FromDigits@ Flatten[IntegerDigits@ Length[#] & /@ Split@ IntegerDigits[#, 2]] &, 40] (* _Michael De Vlieger_, Feb 17 2022 *)
%o (PARI) a(n) = { my (d=[], r); while (n, n\=2^r=valuation(n+n%2, 2); d=concat(digits(r), d)); fromdigits(d) } \\ _Rémy Sigrist_, Feb 17 2022
%o (Python)
%o from itertools import groupby
%o def A318927(n): return int(''.join(str(len(list(g))) for k, g in groupby(bin(n)[2:]))) # _Chai Wah Wu_, Mar 11 2022
%Y Cf. A227736, A318926, A101211.
%K nonn,base
%O 1,2
%A _N. J. A. Sloane_, Sep 09 2018
|