login
A305493
A binary encoding of the decimal representation of a number: for any number n >= 0, consider its decimal representation and replace each 9 with "111111111" and each other digit d with a "0" followed by d "1"s and interpret the result as a binary string.
1
0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 2, 5, 11, 23, 47, 95, 191, 383, 767, 1023, 6, 13, 27, 55, 111, 223, 447, 895, 1791, 2047, 14, 29, 59, 119, 239, 479, 959, 1919, 3839, 4095, 30, 61, 123, 247, 495, 991, 1983, 3967, 7935, 8191, 62, 125, 251, 503, 1007, 2015
OFFSET
0,3
COMMENTS
This sequence is a permutation of the nonnegative numbers.
The inverse sequence, say b, satisfies b(n) = A001202(n+1) for n = 0..1022, but b(1023) = 19 whereas A001202(1024) = 10.
The first known fixed points are: 0, 1, 65010; they all belong to A037308.
This encoding can be applied to any base b > 1 (when b = 2, we obtain the identity function) as well as to the factorial base and to the primorial base.
FORMULA
A000120(a(n)) = A007953(n).
a(A051885(k)) = 2^k - 1 for any k >= 0.
a(A002275(k)) = A002450(k) for any k >= 0.
a(10 * n) = 2 * a(n).
EXAMPLE
For n = 1972:
- the digit 1 is replaced by "01",
- the digit 9 is replaced by "111111111",
- the digit 7 is replaced by "01111111",
- the digit 2 is replaced by "011",
- hence we obtain the binary string "0111111111101111111011",
- and a(1972) = 2096123.
MATHEMATICA
tb=Table[n->PadRight[{0}, n+1, 1], {n, 9}]/.PadRight[{0}, 10, 1]-> PadRight[ {}, 9, 1]; Table[FromDigits[IntegerDigits[n]/.tb//Flatten, 2], {n, 0, 60}] (* Harvey P. Dale, Jul 31 2018 *)
PROG
(PARI) a(n, base=10) = my (b=[], d=digits(n, base)); for (i=1, #d, if (d[i]!=base-1, b=concat(b, 0)); b=concat(b, vector(d[i], k, 1))); fromdigits(b, 2)
/* inverse */ b(n, base=10) = my (v=0, p=1); while (n, my (d = min(valuation(n+1, 2), base-1)); v += p * d; n \= 2^min(base-1, 1+d); p *= base); v
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Jun 02 2018
STATUS
approved