OFFSET
0,3
COMMENTS
LINKS
T. D. Noe, Table of n, a(n) for n = 0..1023
FORMULA
a(2^n + b) = n + b + 1 for b = 0 or 1.
a(2^n - b) = 2^n - b for b = 1 or 2.
EXAMPLE
For example, an a(n) of 3 means that n should be inserted after the 3rd element of the list to keep the elements lexicographically ordered.
[] (Initial empty list)
[0] (Zero inserted at the beginning: a(0) = 0)
[0, 1] (One inserted after element 1: a(1) = 1)
[0, 1, 10] (Two inserted after element 2: a(2) = 2)
[0, 1, 10, 11] (Three inserted after element 3: a(3) = 3)
[0, 1, 10, 100, 11] (Four inserted after element 3: a(4) = 3)
MATHEMATICA
lst = {}; Table[s = IntegerString[n, 2]; lst = Sort[Append[lst, s]]; Position[lst, s][[1, 1]] - 1, {n, 0, 63}] (* T. D. Noe, Apr 19 2011 *)
PROG
(Python)
l = []
for i in range(17):
b = bin(i)[2:]
l.append(b)
l.sort()
print(l.index(b))
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Grant Garcia, Mar 24 2011
EXTENSIONS
Program added by Grant Garcia, Mar 30 2011
Edited by Grant Garcia, Apr 13 2011
STATUS
approved