login
Length of sections with the same initial and final digits in the decimal expansion of Pi.
6

%I #18 Jan 14 2025 09:06:29

%S 10,22,19,11,18,21,5,11,2,7,20,14,6,44,4,34,17,10,6,15,8,12,10,4,11,

%T 13,21,24,16,5,11,17,19,39,33,17,4,8,7,3,20,10,6,4,21,20,11,12,3,5,4,

%U 5,27,2,3,21,7,22,13,7,6,8,4,4,8,2,2,8,4,4,11,3,9,28,7,49,30,3,5,8,24,5,11,3

%N Length of sections with the same initial and final digits in the decimal expansion of Pi.

%e Start with decimal expansion of Pi: s0=3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0,2,8,8,4,1,9,7,1,6,9,3,9,9,3,7,5,1,0,5,8,2,0,9,7,4,9,4,4,5,...

%e Divide s0 to the sections with the same final digits: s={3,1,4,1,5,9,2,6,5,3}, {5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5}, {0,2,8,8,4,1,9,7,1,6,9,3,9,9,3,7,5,1,0}, {5,8,2,0,9,7,4,9,4,4,5},...

%e Then a(n) = length of [s(n)]: 10,22,19,11,...

%t pi = RealDigits[Pi, 10, 1000][[1]]; lst = {}; f := Block[{k = Position[pi, pi[[1]]][[2, 1]]}, pi = Drop[pi, k]; k]; Do[lst = {lst, f}, {n, 80}]; Flatten[lst] (* _Robert G. Wilson v_, Mar 29 2005 *)

%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(2*10**5))[:-1] # alternative to above

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

%o def aupton(terms):

%o alst, idx = [], 0

%o for n in range(1, terms+1):

%o digit, idx, c = pi_digits[idx], idx+1, 2

%o while pi_digits[idx] != digit:

%o idx += 1; c += 1

%o assert idx < len(pi_digits), "increase precision"

%o alst.append(c); idx += 1

%o return alst

%o print(aupton(84)) # _Michael S. Branicky_, Oct 22 2021

%Y Cf. A000796, A104866, A104867, A104868, A104869, A104870, A104871.

%K nonn,base

%O 1,1

%A _Zak Seidov_, Mar 29 2005

%E More terms from _Robert G. Wilson v_, Mar 29 2005