・ It is a little paper for one month of program history. ・ I am studying agriculture at university. ・ I am a sophomore in college.
I will honestly investigate whether the numbers appearing in the Fibonacci sequence are biased. Since it is a brute force attack, no mathematical basis is given. (Not given) By the way F_0=0 Let's consider the Fibonacci sequence of F_1 = 1.
I will look it up in my own program as well as studying the program. First I checked the number of digits
As a result of investigation, it became as follows.
F_10 :2 digits
F_100 :21 digits
F_1000 :209 digits
F_10000 :20899 digits
F_100000 :208988 digits
It seems that the number of digits / n has converged. (It might be interesting to look it up) The program used to investigate below
def fibo(N):
A=0
B=1
if N==0:
return 0
elif N==1:
return 1
for i in range(1,N+1):
if i%2==0:
A+=B
else:
B+=A
if N%2==1:
return B
else:
return A
N=int(input())
ans=str(fibo(N))
print(len(ans))
Let's investigate. Let [a, b, c, d, e, f, g, h, i, j] = [number of 0s, number of 1s, ..., number of 9s].
F_10 : [0, 0, 0, 0, 0, 2, 0, 0, 0, 0]
F_100 : [1, 3, 3, 1, 3, 3, 1, 2, 2, 2]
F_1000 : [20, 13, 21, 18, 21, 23, 26, 21, 20, 26]
F_10000 : [217, 199, 228, 254, 194, 202, 217, 198, 197, 184]
F_100000 : [2109, 2135, 2149, 2096, 2023, 2053, 2051, 2034, 2131, 2118]
There seems to be no variation. Click here for the program used
def check(N):
M=str(N)
cnt=[0]*10
for i in range(10):
cnt[i]+=M.count(str(i))
return cnt
Well as it is.
Finally, let's count the numbers that appear from F_0 to F_n. Programs to use below
def fc(N):
cnt=[1,0,0,0,0,0,0,0,0,0]
if N==0:
return cnt
else:
A=0#Even number
B=1#Odd number
for i in range(1,N+1):
if i%2==0:
A+=B
X=check(A)
for i in range(10):
cnt[i]+=X[i]
else:
B+=A
X=check(B)
for i in range(10):
cnt[i]+=X[i]
return cnt
Confirmation that it matches for the time being. Display the numbers used from F_0 to F_10 and check with the human eye whether they are added properly
F_0 : [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
F_1 : [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
F_2 : [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
F_3 : [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
F_4 : [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
F_5 : [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
F_6 : [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
F_7 : [0, 1, 0, 1, 0, 0, 0, 0, 0, 0]
F_8 : [0, 1, 1, 0, 0, 0, 0, 0, 0, 0]
F_9 : [0, 0, 0, 1, 1, 0, 0, 0, 0, 0]
F_10 : [0, 0, 0, 0, 0, 2, 0, 0, 0, 0]
F_0 ~ F_10 : [1, 4, 2, 3, 1, 3, 0, 0, 1, 0]
That's right for the program. Was good.
Let's count. It became as follows.
F_0 ~ F_10 : [1, 4, 2, 3, 1, 3, 0, 0, 1, 0]
F_0 ~ F_100 : [108, 139, 107, 101, 113, 95, 96, 116, 93, 104]
F_0 ~ F_1000 : [10475, 10696, 10495, 10476, 10431, 10516, 10433, 10576, 10350, 10303]
F_0 ~ F_10000 : [1045480, 1048189, 1045589, 1046744, 1044979, 1044900, 1042460, 1045481, 1043942, 1044171]
F_0 ~ F_20000 : [4179559, 4186491, 4179239, 4183641, 4180815, 4181752, 4178221, 4176724, 4176043, 4180145]
F_0 ~ F_30000 : [9406594, 9413374, 9403056, 9411723, 9406486, 9407934, 9403646, 9398938, 9397857, 9402484]
F_0 ~ F_40000 : [16719279, 16734411, 16720978, 16726026, 16719794, 16722921, 16714455, 16713027, 16711426, 16717999]
F_0 ~ F_50000 : [26119402, 26143034, 26126777, 26131821, 26123096, 26127116, 26119314, 26118936, 26118561, 26119246]
F_0 ~ F_100000 : [The limits of my program]
I tried to fix it to%
F_0 ~ F_10 : [6.667, 26.667, 13.333, 20.0, 6.667, 20.0, 0.0, 0.0, 6.667, 0.0]
F_0 ~ F_100 :[10.075, 12.966, 9.981, 9.422, 10.541, 8.862, 8.955, 10.821, 8.675, 9.701]
F_0 ~ F_1000 : [10.0, 10.211, 10.019, 10.001, 9.958, 10.039, 9.96, 10.096, 9.881, 9.836]
F_0 ~ F_10000 : [10.003, 10.029, 10.004, 10.015, 9.998, 9.997, 9.974, 10.003, 9.988, 9.99]
F_0 ~ F_20000 : [9.998, 10.015, 9.998, 10.008, 10.001, 10.004, 9.995, 9.992, 9.99, 10.0]
F_0 ~ F_30000 :[10.001, 10.009, 9.998, 10.007, 10.001, 10.003, 9.998, 9.993, 9.992, 9.997]
F_0 ~ F_40000 : [10.0, 10.009, 10.001, 10.004, 10.0, 10.002, 9.997, 9.996, 9.995, 9.999]
F_0 ~ F_50000 :[9.998, 10.007, 10.001, 10.003, 9.999, 10.001, 9.998, 9.998, 9.998, 9.998]
There seems to be no bias. I would like to keep it as a memo if I do something in the practice of the program in the future> <
Recommended Posts