Пример #1
0
def problem37():
    found = set()
    primes = iPrime()
    # The primes 2,3,5,7 are not candidates, but they could be the result of a
    # truncation.
    primesOfInterest = {next(primes), next(primes), next(primes), next(primes)}
    for q in primes:
        if isMadeOfOddOrWithLeading2(q):
            primesOfInterest.add(q)
            if all(p in primesOfInterest for p in leftTruncates(q)) and all(p in primesOfInterest for p in rightTruncates(q)):
                found.add(q)
                if len(found) > 10:
                    return sum(found)
Пример #2
0
def problem60():
	primes = [3,7]
	primeGen = iPrime()
	next(primeGen); next(primeGen); next(primeGen); next(primeGen) # 2 and 5 are primes that will never concatinate
	concatenate = {2:set(),3:set(),5:set(),7:{3}}
	def concatenateWith(a):
		concatenate[a] = {p for p in primes[:-1] if remarkable(a,p)}
		return concatenate[a]
	for a in primeGen:
		primes.append(a)
		A = concatenateWith(a)
		for b in A:
			B = concatenate[b] & A
			for c in B:
				C = concatenate[c] & B
				for d in C:
					D = concatenate[d] & C
					for e in D:
						return sum([a,b,c,d,e])
Пример #3
0
def problem7a():
	''' solution using an iterator '''
	for index,p in enumerate(iPrime()):
		if index + 1 == 10001:
			return p