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]


def euler_058():
    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


if __name__ == "__main__":
    print("e058.py: " + str(euler_058()))
    assert(euler_058() == 26241)
