import random M = 1000 ps = set(primes(3, M+1)) #random.shuffle(ps) #järjestys voi muuttaa tulosta toGet = set(range(6, M+2, 2)) a = [] def getBestPrime(): bestP = None bestVal = 0 for p in ps: v = sum(1 for x in a+[p] if x+p in toGet) if bestP==None or v>bestVal: bestVal = v bestP = p return bestP while len(toGet): p = getBestPrime() ps.remove(p) a.append(p) for x in a: if x+p in toGet: toGet.remove(x+p) print (len(a)) print (sorted(a))