Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ShashkovS/461ebda65fed1b25f4604a16e392c68d to your computer and use it in GitHub Desktop.
Save ShashkovS/461ebda65fed1b25f4604a16e392c68d to your computer and use it in GitHub Desktop.
статистика по знакам числа 𝜋.py
from decimal import getcontext, Decimal as D
from collections import Counter
N = 100000
getcontext().prec = N + 10
a, b, t, p, d = D('1'), D('1') / D('2').sqrt(), D('0.25'), D('1'), D('0.5')
for i in range(N.bit_length()):
a, b, t, p = (a + b) * d, (a * b).sqrt(), t - p * (a - (a + b) * d) ** 2, 2 * p
res = str((a + b) ** 2 / (D('4') * t))
dg = res[2:N+2]
# print(res[0:N + 1])
# Четвёрхки
ctr = Counter(dg[i:i+4] for i in range(len(dg)-4))
sctr = sorted(ctr.items(), key=lambda x: -x[-1])
print(sctr[:50])
print(sctr[-50:])
# [('5485', 24), ('1766', 24), ('4608', 23), ('1825', 23), ('2103', 23), ('3236', 23), ('5371', 22), ('0359', 22), ('2887', 22), ...]
# [..., ('8808', 2), ('0369', 2), ('4115', 2), ('2425', 2), ('8041', 2), ('4325', 2), ('6838', 1), ('5971', 1), ('6716', 1)]
# Пятёрки
ctr = Counter(dg[i:i+5] for i in range(len(dg)-5))
sctr = sorted(ctr.items(), key=lambda x: -x[-1])
print(sctr[:50])
print(sctr[-50:])
# [('17663', 8), ('91465', 8), ('40359', 7), ('47772', 7), ('06965', 7), ('40230', 7), ('56251', 7), ('34052', 7), ('14654', 6), ...]
# [..., ('58035', 1), ('12790', 1), ('90913', 1), ('67420', 1), ('74208', 1), ('20805', 1), ('80565', 1), ('54936', 1), ('36246', 1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment