Exemplo n.º 1
0
Arquivo: 58.py Projeto: jaibot/euler
#!/usr/bin/env python
#By Jai Dhyani
#Automatically generated on 2010-11-26

import primgen

if __name__ == "__main__":
    num=3
    corner=1
    inc=2
    pcount=1.0
    diameter=1
    while True:
        num+=inc
        corner+=1
        if corner%4==0:
            inc+=2
            diameter+=2
        pcount+=primgen.is_prime(num)
        print num,pcount/(corner+1)
        if pcount/(corner+1)<0.1:
            print diameter
            exit(0)
Exemplo n.º 2
0
Arquivo: 51.py Projeto: jaibot/euler
# you need to convert this to get_families
def get_families(n):
    rep = [int(c) for c in str(n)]
    digits = set(rep)
    for d in digits:
        family = set()
        for v in xrange(10):
            relation = rep[::-1]
            for i, r in enumerate(relation):
                if r == d:
                    if i == len(relation) - 1 and v == 0:
                        continue
                    relation[i] = v
            v = sum([pow(10, i) * x for i, x in enumerate(relation)])
            family.add(v)
        print family
        yield family


pg = primgen.prime_generator()
for p in pg:
    if p >= 56003:
        fams = get_families(p)
        for f in fams:
            fam_success_size = sum([primgen.is_prime(n) for n in f])
            print p, fam_success_size
            if fam_success_size >= 8:
                print p
                exit(0)
        print p