-
Notifications
You must be signed in to change notification settings - Fork 1
/
58.py
34 lines (30 loc) · 938 Bytes
/
58.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sympy
def numbers_on_the_diagonal():
x = 1
yield {"datum": x, "side length": 1}
increment = 2
diagonal_primes_found = 0
while True:
for _ in range(4):
x += increment
if sympy.isprime(x):
diagonal_primes_found += 1
side_length = increment + 1
diagonal_population = side_length * 2 - 1
yield {
"x": x,
"side_length": side_length,
"diagonal_population": diagonal_population,
"diagonal_primes_found": diagonal_primes_found,
}
increment += 2
if __name__ == "__main__":
d = numbers_on_the_diagonal()
while True:
data = next(d)
try:
if data["diagonal_primes_found"] / data["diagonal_population"] < 0.1:
print(data["side_length"])
break
except KeyError:
pass