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.

A342242 For any n > 0, a(n) is the least positive number whose binary expansion is both a prefix and a suffix of the binary expansion of n; a(0) = 0.

This page as a plain text file.
%I A342242 #11 Mar 07 2021 17:46:42
%S A342242 0,1,2,1,4,1,6,1,8,1,2,1,12,1,14,1,16,1,2,1,20,1,2,1,24,1,26,1,28,1,
%T A342242 30,1,32,1,2,1,4,1,2,1,40,1,2,1,44,1,2,1,48,1,50,1,52,1,6,1,56,1,58,1,
%U A342242 60,1,62,1,64,1,2,1,4,1,2,1,72,1,2,1,4,1,2,1
%N A342242 For any n > 0, a(n) is the least positive number whose binary expansion is both a prefix and a suffix of the binary expansion of n; a(0) = 0.
%C A342242 All terms belong to A091065.
%H A342242 Rémy Sigrist, <a href="/A342242/b342242.txt">Table of n, a(n) for n = 0..8192</a>
%H A342242 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F A342242 a(n) = 1 iff n is an odd number.
%F A342242 a(n) <= n with equality iff n belongs to A091065.
%F A342242 a(n) = n mod 2^A342241(n).
%F A342242 a(a(n)) = a(n).
%e A342242 For n = 814:
%e A342242 - the binary expansion of 814 is "1100101110",
%e A342242 - "1" does not match "0",
%e A342242 - "11" does not match "10",
%e A342242 - "110" matches "110",
%e A342242 - so the binary representation of a(814) is "110",
%e A342242 - and a(814) = 6.
%o A342242 (PARI) a(n) = { my (b=if (n, binary(n), [0])); for (w=1, oo, if (b[1..w]==b[#b+1-w..#b], return (fromdigits(b[1..w],2)))) }
%o A342242 (Python)
%o A342242 def a(n):
%o A342242   b = bin(n)[2:]
%o A342242   for i in range(1, len(b)+1):
%o A342242     if b[:i] == b[-i:]: return int(b[:i], 2)
%o A342242 print([a(n) for n in range(80)]) # _Michael S. Branicky_, Mar 07 2021
%Y A342242 Cf. A091065, A342241, A342241.
%K A342242 nonn,base,easy
%O A342242 0,3
%A A342242 _Rémy Sigrist_, Mar 07 2021