Exemplo n.º 1
0
def pandigital():
    for a2 in d2:
        aa2 = "%03d" % a2
        for a3 in d3:
            aa3 = "%03d" % a3
            if aa2[1:] != aa3[0:-1]: continue
            for a5 in d5:
                aa5 = "%03d" % a5
                if aa3[1:] != aa5[0:-1]: continue
                for a7 in d7:
                    aa7 = "%03d" % a7
                    if aa5[1:] != aa7[0:-1]: continue
                    for a11 in d11:
                        aa11 = "%03d" % a11
                        if aa7[1:] != aa11[0:-1]: continue
                        for a13 in d13:
                            aa13 = "%03d" % a13
                            if aa11[1:] != aa13[0:-1]: continue
                            for a17 in d17:
                                aa17 = "%03d" % a17
                                if aa13[1:] != aa17[0:-1]: continue
                                trial = aa2 + aa3[2] + aa5[2] + aa7[2] + aa11[
                                    2] + aa13[2] + aa17[2]
                                c = primes.countset(trial)
                                if max(c.itervalues()) == 1:
                                    for a in "0123456789":
                                        if not c.has_key(a):
                                            yield a + trial
                                            break
                                    else:
                                        print "error in %s" % trial
Exemplo n.º 2
0
def specialPowerSet(s):
    while s.count(3) >= 2:
        s.remove(3)
        s.remove(3)
        s.append(9)
    while s.count(2) >= 3:
        s.remove(2)
        s.remove(2)
        s.remove(2)
        s.append(8)
    if s.count(2) >= 1 and s.count(3) >= 1:
        s.remove(2)
        s.remove(3)
        s.append(6)
    c = primes.countset(s)
    if all(a == 1 for a in c.itervalues()):
        yield s
    else:
        L = len(s)
        xrl = xrange(L)
        ss = set()
        for i in xrange(1 << L):
            if i == 0: continue
            a = product(s[j] for j in xrl if (i & (1 << j)))
            #if not a in ss :
            #ss.add(a)
            b = [s[j] for j in xrl if (i & (1 << j)) == 0]
            yield sorted([a] + b)
Exemplo n.º 3
0
def specialPowerSet(s) :
	while s.count(3) >= 2 :
		s.remove(3)
		s.remove(3)
		s.append(9)
	while s.count(2) >= 3 :
		s.remove(2)
		s.remove(2)
		s.remove(2)
		s.append(8)
	if s.count(2) >= 1 and s.count(3) >= 1 :
		s.remove(2)
		s.remove(3)
		s.append(6)
	c = primes.countset(s)
	if all(a == 1 for a in c.itervalues()) :
		yield s
	else :
		L = len(s)
		xrl = xrange(L)
		ss = set()
		for i in xrange(1 << L):
			if i == 0 : continue
			a = product(s[j] for j in xrl if (i & (1 << j)))
			#if not a in ss :
			#ss.add(a)
			b = [ s[j] for j in xrl if (i & (1 << j)) == 0 ]
			yield sorted([a] + b)
Exemplo n.º 4
0
def pandigital() :
	for a2 in d2 :
		aa2 = "%03d" % a2
		for a3 in d3 :
			aa3 = "%03d" % a3
			if aa2[1:] != aa3[0:-1] : continue
			for a5 in d5 :
				aa5 = "%03d" % a5
				if aa3[1:] != aa5[0:-1] : continue
				for a7 in d7 :
					aa7 = "%03d" % a7
					if aa5[1:] != aa7[0:-1] : continue
					for a11 in d11 :
						aa11 = "%03d" % a11
						if aa7[1:] != aa11[0:-1] : continue
						for a13 in d13 :
							aa13 = "%03d" % a13
							if aa11[1:] != aa13[0:-1] : continue
							for a17 in d17 :
								aa17 = "%03d" % a17
								if aa13[1:] != aa17[0:-1] : continue
								trial = aa2 + aa3[2] + aa5[2] + aa7[2] + aa11[2] + aa13[2] + aa17[2]
								c = primes.countset(trial)
								if max(c.itervalues()) == 1 :
									for a in "0123456789" :
										if not c.has_key(a) :
											yield a + trial
											break
									else :
										print "error in %s" % trial
Exemplo n.º 5
0
import primes

s = set()
for i in range(12, 98):
    si = "%02d" % i
    for j in range(123, 987):
        r = i * j
        sj = "%03d" % j
        sr = "%04d" % r
        p = si + sj + sr
        if p.find("0") == -1:
            c = primes.countset(p)
            if max(c.itervalues()) == 1:
                print i, j, r, p
                s.add(r)

for i in range(1, 10):
    si = "%01d" % i
    for j in range(1000, 10000):
        r = i * j
        sj = "%04d" % j
        sr = "%04d" % r
        p = si + sj + sr
        if p.find("0") == -1:
            c = primes.countset(p)
            if max(c.itervalues()) == 1:
                print i, j, r, p
                s.add(r)

for pp in s:
    print pp
Exemplo n.º 6
0
import primes

d17 = [
    d for d in range(17, 1000, 17)
    if max(primes.countset("%03d" % d).itervalues()) == 1
]
d13 = [
    d for d in range(13, 1000, 13)
    if max(primes.countset("%03d" % d).itervalues()) == 1
]
d11 = [
    d for d in range(132, 1000, 11)
    if max(primes.countset("%03d" % d).itervalues()) == 1
]
d7 = [
    d for d in range(7, 1000, 7)
    if max(primes.countset("%03d" % d).itervalues()) == 1
]
d5 = [
    d for d in range(5, 1000, 5)
    if max(primes.countset("%03d" % d).itervalues()) == 1
]
d3 = [
    d for d in range(3, 1000, 3)
    if max(primes.countset("%03d" % d).itervalues()) == 1
]
d2 = [
    d for d in range(2, 1000, 2)
    if max(primes.countset("%03d" % d).itervalues()) == 1
]
Exemplo n.º 7
0
import primes

for i in range(1, 100000):
    s = str(1 * i) + str(2 * i)
    if len(s) == 9:
        c = primes.countset(s)
        if max(c.itervalues()) == 1 and s.find("0") == -1:
            print s
Exemplo n.º 8
0
import primes

d17 = [d for d in range(17, 1000, 17) if max(primes.countset("%03d" % d).itervalues()) == 1 ]
d13 = [d for d in range(13, 1000, 13) if max(primes.countset("%03d" % d).itervalues()) == 1 ]
d11 = [d for d in range(132, 1000, 11) if max(primes.countset("%03d" % d).itervalues()) == 1 ]
d7 = [d for d in range(7, 1000, 7) if max(primes.countset("%03d" % d).itervalues()) == 1 ]
d5 = [d for d in range(5, 1000, 5) if max(primes.countset("%03d" % d).itervalues()) == 1 ]
d3 = [d for d in range(3, 1000, 3) if max(primes.countset("%03d" % d).itervalues()) == 1 ]
d2 = [d for d in range(2, 1000, 2) if max(primes.countset("%03d" % d).itervalues()) == 1 ]

a = set()
b = set()
for i in d17 :
	s17 = "%03d" % i
	for j in d13 :
		s13 = "%03d" % j
		if s13[1:3] == s17[0:2] :
			a.add(i)
			b.add(j)
d17 = sorted([aa for aa in a])
d15 = sorted([bb for bb in b])

a = set()
b = set()
for i in d13 :
	s13 = "%03d" % i
	for j in d11 :
		s11 = "%03d" % j
		if s11[1:3] == s13[0:2] :
			a.add(i)
			b.add(j)
Exemplo n.º 9
0
import primes

s = set()
for i in range(12, 98) :
	si = "%02d" % i
	for j in range(123, 987) :
		r = i * j
		sj = "%03d" % j
		sr = "%04d" % r
		p = si + sj + sr
		if p.find("0") == -1 :
			c = primes.countset(p)
			if max(c.itervalues()) == 1 :
				print i, j, r, p
				s.add(r)

for i in range(1, 10) :
	si = "%01d" % i
	for j in range(1000, 10000) :
		r = i * j
		sj = "%04d" % j
		sr = "%04d" % r
		p = si + sj + sr
		if p.find("0") == -1 :
			c = primes.countset(p)
			if max(c.itervalues()) == 1 :
				print i, j, r, p
				s.add(r)