<reponame>nymoral/euler
from utils import PrimeGen, Timed


class DiagGen(object):
    def __init__(self):
        self.seed = 3
        self.increment = 2
        self.seed_increment = 2

    def __iter__(self):
        return self

    def __next__(self):
        diag = (
            self.seed,
            self.seed + self.increment,
            self.seed + self.increment * 2,
            self.seed + self.increment * 3,
        )
        self.increment += 2
        self.seed_increment += 8
        self.seed += self.seed_increment
        return diag


if __name__ == '__main__':
    pg = PrimeGen()
    dg = DiagGen()
    n_total = 1
    n_primes = 0
    side_length = 1
    with Timed():
        for i, d in enumerate(dg):
            side_length += 2
            n_total += len(d)
            for n in d:
                if pg.is_prime(n):
                    n_primes += 1
            ratio = n_primes / n_total
            if ratio < 0.1:
                print(side_length, ratio)
                break


from utils import PrimeGen, Timed


class DiagGen(object):
    def __init__(self):
        self.seed = 3
        self.increment = 2
        self.seed_increment = 2

    def __iter__(self):
        return self

    def __next__(self):
        diag = (
            self.seed,
            self.seed + self.increment,
            self.seed + self.increment * 2,
            self.seed + self.increment * 3,
        )
        self.increment += 2
        self.seed_increment += 8
        self.seed += self.seed_increment
        return diag


if __name__ == '__main__':
    pg = PrimeGen()
    dg = DiagGen()
    n_total = 1
    n_primes = 0
    side_length = 1
    with Timed():
        for i, d in enumerate(dg):
            side_length += 2
            n_total += len(d)
            for n in d:
                if pg.is_prime(n):
                    n_primes += 1
            ratio = n_primes / n_total
            if ratio < 0.1:
                print(side_length, ratio)
                break