def extendPotentialPrimes(fname, maxIterations, allowedMiss): ps = findPrimes(fname, allowedMiss) pm = PyMachine.PyMachine(maxIterations, 1, maxIterations, 0, maxIterations) extended = [] for program, plen in ps: pm.load(long(program), int(plen)) pm.execute() oldp = -1 outputs = [] nrisp = 0 v = pm.getOutput() print[x for x in v] for p in v: if p <= oldp: break isp = PyMachine.checkPrime(p) nrisp += isp outputs.append((p, isp)) if nrisp: extended.append((float(nrisp) / len(outputs), nrisp, len(outputs), outputs, program, plen)) extended.sort() extended.reverse() return extended
def findPrimes(fname, allowedMiss=0): ps = [] f = open(fname) i = 0 j = 0 for l in f: i += 1 nr, depth, program, seq = l.split(' ', 3) seq = seq.strip() xs = [int(x) for x in seq.split()] if len(set(xs)) != 10: continue good = True for x in xs: if x < 1: good = False break if not good: continue j += 1 misses = 0 for x in xs: if not PyMachine.checkPrime(x): misses += 1 if misses > allowedMiss: break if misses <= allowedMiss: print misses, xs, nr, depth, program ps.append((program, depth)) print i, j f.close() return ps
return False return True def extendPotentialPrimes(fname, maxIterations, allowedMiss): ps = findPrimes(fname, allowedMiss) pm = PyMachine.PyMachine(maxIterations, 1, maxIterations, 0, maxIterations) extended = [] for program, plen in ps: pm.load(long(program), int(plen)) pm.execute() oldp = -1 outputs = [] nrisp = 0 v = pm.getOutput() print [x for x in v] for p in v: if p <= oldp: break isp = PyMachine.checkPrime(p) nrisp += isp outputs.append((p, isp)) if nrisp: extended.append((float(nrisp) / len(outputs), nrisp, len(outputs), outputs, program, plen)) extended.sort() extended.reverse() return extended