Last active
December 18, 2015 02:19
-
-
Save kenbolton/5710648 to your computer and use it in GitHub Desktop.
Worked with @thisgeek and @waltd3 to put together this little snippet that solves [OpenCourseware CS 600](http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset1a.pdf)
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
def main(): | |
list_of_primes = [2] | |
while len(list_of_primes) < 1000: | |
if list_of_primes[-1] % 2 == 0: | |
value = list_of_primes[-1] + 1 | |
else: | |
value += 2 | |
is_prime = True | |
for i in list_of_primes: | |
if i > value * 0.5: | |
break | |
if value % i == 0: | |
is_prime = False | |
break | |
if is_prime: | |
list_of_primes.append(value) | |
return list_of_primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment