login
A318927
Take the binary expansion of n, starting with the most significant bit, and concatenate the lengths of the runs.
6
1, 11, 2, 12, 111, 21, 3, 13, 121, 1111, 112, 22, 211, 31, 4, 14, 131, 1211, 122, 1112, 11111, 1121, 113, 23, 221, 2111, 212, 32, 311, 41, 5, 15, 141, 1311, 132, 1212, 12111, 1221, 123, 1113, 11121, 111111, 11112, 1122, 11211, 1131, 114, 24, 231, 2211, 222, 2112
OFFSET
1,2
COMMENTS
Obviously this compressed notation is useful only for n < 1023. A101211 is a version which works for all n.
LINKS
EXAMPLE
n, binary, run lengths, -> a(n)
1, [1], [1] -> 1
2, [1, 0], [1, 1] -> 11
3, [1, 1], [2] -> 2
4, [1, 0, 0], [1, 2] -> 12
5, [1, 0, 1], [1, 1, 1] -> 111
6, [1, 1, 0], [2, 1] -> 21
7, [1, 1, 1], [3] -> 3
...
MATHEMATICA
Array[FromDigits@ Flatten[IntegerDigits@ Length[#] & /@ Split@ IntegerDigits[#, 2]] &, 40] (* Michael De Vlieger, Feb 17 2022 *)
PROG
(PARI) a(n) = { my(d=[], r); while(n, n>>=r=valuation(n+n%2, 2); d=concat(digits(r), d)); fromdigits(d) } \\ Rémy Sigrist, Feb 17 2022, edited by M. F. Hasler, Mar 11 2025
(Python)
from itertools import groupby
def A318927(n): return int(''.join(str(len(list(g))) for k, g in groupby(bin(n)[2:]))) # Chai Wah Wu, Mar 11 2022
CROSSREFS
Cf. A101211 (without concatenation, as rows), A227736 (rows reversed), A318926 (reverse concatenation).
Cf. A382255 (Heinz numbers instead of concatenation of the run lengths).
Sequence in context: A330521 A338191 A360227 * A267320 A303785 A262369
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Sep 09 2018
STATUS
approved