login
Starting position (after the decimal point) of the first n-digit palindrome in the decimal expansion of Pi.
1

%I #31 Jan 10 2022 14:56:09

%S 0,24,1,43,19,762,640,3732,6577,16061,247146,273840,879326,5380812,

%T 10593200,171880711,105176740,517694394,559015193,824827924

%N Starting position (after the decimal point) of the first n-digit palindrome in the decimal expansion of Pi.

%C The first 10-digit palindrome in the decimal expansion of Pi (0136776310) first appears at a palindromic position (16061).

%e a(2) = 24 because the first 2-digit palindrome in the decimal expansion of Pi (33) starts 24 digits after the decimal point.

%e 3.14159265358979323846264(33)...

%t With[{d = First@ RealDigits@ N[Pi, 10^6]}, Prepend[DeleteCases[Rest@ #, 0], First@ #] &@ Flatten@ Map[If[Length@ # == 0, 0, #[[1, 1]] - 1] &@ SequencePosition[d, #] &, Table[If[Length@ # == 0, {}, First@ #] &@ Select[Partition[d, n, 1], # == Reverse@ # &], {n, 20}]]] (* _Michael De Vlieger_, Jan 07 2017, Version 10.1 *)

%o (Python)

%o from sympy import S

%o # download https://stuff.mit.edu/afs/sipb/contrib/pi/pi-billion.txt, then

%o # with open('pi-billion.txt', 'r') as f: pi_digits = f.readline()

%o pi_digits = str(S.Pi.n(3*10**5+2))[:-2] # alternative to above

%o pi_digits = pi_digits.replace(".", "")

%o def ispal(s): return s == s[::-1]

%o def a(n):

%o for idx in range(len(pi_digits)-n):

%o if ispal(pi_digits[idx:idx+n]):

%o return int(pi_digits[idx:idx+n]), idx

%o return None, None # Not found: Increase number of digits

%o print([a(n)[1] for n in range(1, 13)]) # _Michael S. Branicky_, Jan 10 2022

%Y Cf. A000796, A002113, A279885.

%K nonn,base,more,less

%O 1,2

%A _Bobby Jacobs_, Jan 06 2017

%E a(14)-a(15) from _Michael De Vlieger_, Jan 07 2017

%E a(16)-a(20) from _Michael S. Branicky_, Jan 10 2022