示例#1
0
def c():
    digits  = set(range(10))
    for d4 in c4():
        for d6 in c6():
            for d8,d9,d10 in c8910():
                if unique([d4,d6,d8,d9,d10]):
                    for d1, d2, d3, d5, d7 in permutate(digits - 
                            set([d4,d6,d8,d9,d10])):
                        yield [d1,d2,d3,d4,d5,d6,d7,d8,d9,d10]
示例#2
0
def find3():
    s = set()
    for each in permutate([1, 2, 3, 4, 5, 6]):
        rs = ring3(each)
        if rs is not None:
            s.add(rs)

    for each in sorted(s):
        print each
示例#3
0
def c():
    digits = set(range(10))
    for d4 in c4():
        for d6 in c6():
            for d8, d9, d10 in c8910():
                if unique([d4, d6, d8, d9, d10]):
                    for d1, d2, d3, d5, d7 in permutate(
                            digits - set([d4, d6, d8, d9, d10])):
                        yield [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10]
示例#4
0
def find3():
    s = set()
    for each in permutate([1,2,3,4,5,6]):
        rs = ring3(each)
        if rs is not None:
            s.add(rs)

    for each in sorted(s):
        print each
示例#5
0
def find5():
    s = set()
    for each in permutate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]):
        rs = ring5(each)
        if rs is not None:
            ds = ''.join(str(d) for d in rs)
            if len(ds) == 16:
                print ds
                s.add(ds)

    return max(s)
示例#6
0
def find5():
    s = set()
    for each in permutate([1,2,3,4,5,6,7,8,9,10]):
        rs = ring5(each)
        if rs is not None:
            ds = ''.join(str(d) for d in rs)
            if len(ds)==16:
                print ds
                s.add(ds)


    return max(s)
示例#7
0
def expr(a, b, c, d):
    from euler import permutate

    rs = set()

    for (op1, op2, op3) in ops_triple():
        for (a,b,c,d) in permutate([a, b, c, d]):
            for t in TREES:
                try:
                    n = t(op1, op2, op3, a, b, c, d)
                    if n > 0 and int(n) == n:
                        rs.add(n)
                except:
                    pass
    return rs
示例#8
0
def expr(a, b, c, d):
    from euler import permutate

    rs = set()

    for (op1, op2, op3) in ops_triple():
        for (a, b, c, d) in permutate([a, b, c, d]):
            for t in TREES:
                try:
                    n = t(op1, op2, op3, a, b, c, d)
                    if n > 0 and int(n) == n:
                        rs.add(n)
                except:
                    pass
    return rs
示例#9
0
'''
9-digit pandigitals are not prime, as 1+2+3+4+5+6+7+8+9=45 is divided by 3
8-digit pandigitals are not prime, as 1+2+3+4+5+6+7+8=36 is divided by 3
so check from 7-digit pandigitals
'''

from euler import isprime, permutate

digits  = range(7,0,-1)
for d in digits:
    for p in permutate(range(d,0,-1)):  # permutate in desc order
        n   = int(''.join(map(str,p)))
        #n   = sum(p[i]*(10**i) for i in range(len(p)))
        if isprime(n):
            print n
            break
示例#10
0
# The number must be of the form
# ABCD.EFGHI where ABCD * 2 = EFGHI

from euler import permutate

for permu in sorted(permutate('987654321'), reverse=True):
    i1, i2 = map(lambda x: int(''.join(x)), [permu[:4], permu[4:]])
    if i1 * 2 == i2:
        print int(''.join(permu))
        break
示例#11
0
'''
9-digit pandigitals are not prime, as 1+2+3+4+5+6+7+8+9=45 is divided by 3
8-digit pandigitals are not prime, as 1+2+3+4+5+6+7+8=36 is divided by 3
so check from 7-digit pandigitals
'''

from euler import isprime, permutate

digits = range(7, 0, -1)
for d in digits:
    for p in permutate(range(d, 0, -1)):  # permutate in desc order
        n = int(''.join(map(str, p)))
        #n   = sum(p[i]*(10**i) for i in range(len(p)))
        if isprime(n):
            print n
            break
示例#12
0
# The number must be of the form
# ABCD.EFGHI where ABCD * 2 = EFGHI

from euler import permutate

for permu in sorted(permutate('987654321'), reverse=True):
    i1, i2  = map(lambda x: int(''.join(x)), [permu[:4], permu[4:]])
    if i1*2 == i2:
        print int(''.join(permu))
        break
示例#13
0
def tryall():
    ps = [p3s, p4s, p5s, p6s, p7s, p8s]
    for each in permutate(ps):
        rs = find(*each)
        if rs is not None:
            return rs
示例#14
0
# only two forms of permutations are possible
# ABC x DE = FGHI
# ABCD x E = FGHI

from euler import permutate

rs = set()
for permu in permutate('123456789'):

    m1, m2, prod = int(''.join(permu[:3])), int(''.join(permu[3:5])), int(
        ''.join(permu[5:]))

    if m1 * m2 == prod:
        print m1, 'x', m2, '=', prod
        rs.add(prod)

    m1, m2, prod = int(''.join(permu[:4])), int(''.join(permu[4:5])), int(
        ''.join(permu[5:]))
    if m1 * m2 == prod:
        print m1, 'x', m2, '=', prod
        rs.add(prod)

print 'All products:', rs
print 'Sum:', sum(rs)
示例#15
0
# only two forms of permutations are possible 
# ABC x DE = FGHI
# ABCD x E = FGHI


from euler import permutate

rs  = set()
for permu in permutate('123456789'):

    m1, m2, prod  = int(''.join(permu[:3])), int(''.join(permu[3:5])), int(''.join(permu[5:]))

    if m1 * m2 == prod:
        print m1, 'x', m2, '=', prod
        rs.add(prod)


    m1, m2, prod  = int(''.join(permu[:4])), int(''.join(permu[4:5])), int(''.join(permu[5:]))
    if m1 * m2 == prod:
        print m1, 'x', m2, '=', prod
        rs.add(prod)
    

print 'All products:', rs
print 'Sum:', sum(rs)
示例#16
0
def tryall():
    ps = [p3s, p4s, p5s, p6s, p7s, p8s]
    for each in permutate(ps):
        rs = find(*each)
        if rs is not None:
            return rs