Advertisement
theussjeng

PS1a

Sep 1st, 2011
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
IDL 0.96 KB | None | 0 0
  1. allprimes = [1, 2, 3]                     # defines a variable as an array of primes
  2. candidate = 5                               # defines a starting candidate
  3. while len(allprimes) < 1000:                # starts a conditional loop under which the following steps will repeat
  4.     for number in allprimes:                # nests another loop -- for each number in the list of primes
  5.         if candidate % number == 0:         # if any number in the array of primes divides evenly into the candidate
  6.             break                           # stop the loop
  7.         else:                               # otherwise
  8.             allprimes.append(candidate)     # append the candidate to the end of the allprimes array
  9.             candidate = candidate + 2       # redefine candidate as its previous value + 2
  10. if len(allprimes) == 1000:                  # when the length of the prime list reaches 1000
  11.     print allprimes[-1]                     # print that last sucker out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement