Created
April 13, 2011 23:55
-
-
Save joeegan/918674 to your computer and use it in GitHub Desktop.
1000th prime number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| odd_numbers = []; | |
| non_primes = []; | |
| i = 1 | |
| while i <= 10000: | |
| i = i + 2 | |
| odd_numbers.append(i) | |
| print len(odd_numbers) | |
| for odd_number in odd_numbers: | |
| divisor = 1 | |
| while divisor < odd_number-1: | |
| divisor = divisor + 1; | |
| # print "trying " + str(odd_number) + " % " + str(divisor) | |
| if odd_number % divisor == 0: | |
| # print str(odd_number) + " is not a prime, it divides evenly by "+str(divisor) | |
| non_primes.append(odd_number) | |
| break | |
| primes_set = set(odd_numbers).difference(non_primes) | |
| primes_list = list(primes_set) | |
| primes_list.sort() | |
| primes_list.insert(0,2) | |
| print primes_list | |
| print primes_list[999] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment