OFFSET
0,3
COMMENTS
This sequence gives the length of the least nonempty prefix that is also a suffix of the binary expansion of a number.
LINKS
FORMULA
EXAMPLE
For n = 42:
- the binary representation of 42 is "101010",
- the first bit ("1") and the last bit ("0") do not match,
- the first 2 bits ("10") and the last 2 bits ("10") match,
- so a(42) = 2.
PROG
(PARI) a(n) = { my (b=if (n, binary(n), [0])); for (w=1, oo, if (b[1..w]==b[#b+1-w..#b], return (w))) }
(Python)
def a(n):
b = bin(n)[2:]
for i in range(1, len(b)+1):
if b[:i] == b[-i:]: return i
print([a(n) for n in range(87)]) # Michael S. Branicky, Mar 07 2021
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Mar 07 2021
STATUS
approved