OFFSET
1,1
COMMENTS
Given two words X,Y in {0,1}^N, the distance d(X,Y) is the least integer K such that there exists a word M with X=UM and Y=MV and |U|=|V|=K. Define a(N)=sum(d(X,Y); X,Y in {0,1}^N).
LINKS
Eric Weisstein's World of Mathematics, de Bruijn Sequence.
EXAMPLE
d(0,0)=0, d(0,1)=1, d(1,0)=1, d(1,1)=0, hence a(1)=0+1+1+0=2.
d(00,00)=0, d(00,01)=1, d(00,10)=2, d(00,11)=2, d(01,00)=2, d(01,01)=0, d(01,10)=1, d(01,11)=1, d(10,00)=1, d(10,01)=1, d(10,10)=0, d(10,11)=2, d(11,00)=2, d(11,01)=2, d(11,10)=1, d(11,11)=0, hence a(2)=0+1+2+2+2+0+1+1+1+1+0+2+2+2+1+0=18.
PROG
(Python)
from numba import njit
@njit
def d(x, y, n):
for k in range(n):
mask = (1 << (n-k)) - 1
if x & mask == (y >> k): return k
return n
@njit
def a(n):
s = 0
for x in range(2**(n-1)):
for y in range(2**n):
s += d(x, y, n)
return 2*s
print([a(n) for n in range(1, 15)]) # Michael S. Branicky, Feb 18 2021
CROSSREFS
KEYWORD
nonn
AUTHOR
Serge Burckel (burckel(AT)iml.univ-mrs.fr), Nov 19 2000
EXTENSIONS
a(9)-a(21) from Michael S. Branicky, Feb 18 2021
STATUS
approved