cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A342241 a(n) is the least k > 0 such that the first k bits and the last k bits in the binary expansion of n are the same.

This page as a plain text file.
%I A342241 #15 Mar 07 2021 17:10:42
%S A342241 1,1,2,1,3,1,3,1,4,1,2,1,4,1,4,1,5,1,2,1,5,1,2,1,5,1,5,1,5,1,5,1,6,1,
%T A342241 2,1,3,1,2,1,6,1,2,1,6,1,2,1,6,1,6,1,6,1,3,1,6,1,6,1,6,1,6,1,7,1,2,1,
%U A342241 3,1,2,1,7,1,2,1,3,1,2,1,7,1,2,1,7,1,2
%N A342241 a(n) is the least k > 0 such that the first k bits and the last k bits in the binary expansion of n are the same.
%C A342241 This sequence gives the length of the least nonempty prefix that is also a suffix of the binary expansion of a number.
%H A342241 Rémy Sigrist, <a href="/A342241/b342241.txt">Table of n, a(n) for n = 0..8192</a>
%H A342241 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F A342241 a(n) = 1 iff n = 0 or n is odd.
%F A342241 a(n) <= A070939(n) with equality iff n belongs to A091065.
%F A342241 a(n) = A070939(A342242(n)).
%e A342241 For n = 42:
%e A342241 - the binary representation of 42 is "101010",
%e A342241 - the first bit ("1") and the last bit ("0") do not match,
%e A342241 - the first 2 bits ("10") and the last 2 bits ("10") match,
%e A342241 - so a(42) = 2.
%o A342241 (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))) }
%o A342241 (Python)
%o A342241 def a(n):
%o A342241   b = bin(n)[2:]
%o A342241   for i in range(1, len(b)+1):
%o A342241     if b[:i] == b[-i:]: return i
%o A342241 print([a(n) for n in range(87)]) # _Michael S. Branicky_, Mar 07 2021
%Y A342241 Cf. A003000, A070939, A091065, A342242.
%K A342241 nonn,base,easy
%O A342241 0,3
%A A342241 _Rémy Sigrist_, Mar 07 2021