2019-07-18 20:23:44 +02:00
|
|
|
from lib_prime import is_prime
|
|
|
|
|
|
|
|
|
|
|
|
def get_corner_values(side_length):
|
|
|
|
def get_last_corner_value(side_length):
|
|
|
|
return side_length * side_length
|
|
|
|
|
|
|
|
if side_length == 1:
|
|
|
|
return [1]
|
|
|
|
return [get_last_corner_value(side_length) - i * (side_length - 1)
|
|
|
|
for i in range(0, 4)][::-1]
|
|
|
|
|
2019-07-18 03:29:59 +02:00
|
|
|
|
|
|
|
def euler_058():
|
2019-07-18 20:23:44 +02:00
|
|
|
n = 1
|
|
|
|
count_primes = 0
|
|
|
|
count_total = 0
|
|
|
|
while True:
|
|
|
|
for v in get_corner_values(n):
|
|
|
|
count_total += 1
|
|
|
|
if is_prime(v):
|
|
|
|
count_primes += 1
|
|
|
|
ratio = count_primes / count_total
|
|
|
|
if ratio != 0 and ratio < 0.10:
|
|
|
|
# print("n: {} count_total: {} count_primes: {} ratio: {}"
|
|
|
|
# .format(n, count_total, count_primes, ratio))
|
|
|
|
return n
|
|
|
|
n += 2
|
2019-07-18 03:29:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("e058.py: " + str(euler_058()))
|
2019-07-18 20:23:44 +02:00
|
|
|
assert(euler_058() == 26241)
|