Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # See 'foundPrimes.txt' for what is loaded/saved in this code on each run
- def isPrime(integer):
- global primes;
- for i in range(0,len(primes)):
- if(integer%int(primes[i])==0):
- return False;
- return True;
- def printList(list):
- elements = 0;
- for i in list:
- print i,
- if(elements==10):
- elements = 0;
- print;
- elements += 1;
- def listToString(list):
- output = "";
- for i in list:
- output += str(i) + " ";
- return output[0:len(output)-1];
- print;
- foundPrimes = open('foundPrimes.txt', 'r');
- print 'Previously found primes:';
- primes = foundPrimes.read().split(' ');
- printList(primes);
- print;
- foundPrimes.close();
- start = int(primes[len(primes)-1]);
- limit = 100001;
- for i in range(start, start+limit, 2):
- if(isPrime(i)):
- primes.append(i);
- print '\nUpdated found primes:';
- printList(primes);
- foundPrimes = open('foundPrimes.txt', 'w');
- foundPrimes.write(listToString(primes));
- foundPrimes.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement