Just posted some swift code to a server, in a few hours I should have all the prime numbers from 1 to a billion!

  • 2
    If you are writing something that'll take a few hours to find that many primes look at the sieve of Eratosthenes, you'll find them in a few minutes, if not seconds.

  • 1
    @alwaysmpe thank you! I'll look into this for the next iteration. Right now I'm finding primes by testing the divisibility of each number by the array of primes before it. So 2 isn't divisible by an empty array so it's added, 3 isn't divisible by 2 so 3 is added, 4 is divisible by 2 so it isn't added but 5 isn't divisible by 2 or 3 so it is added, and so on
  • 0
    @evalie cool, you've obviously put some thought into optimisation, prime number sieves will take you a step further
  • 0
    EDIT: even after a few days the code was no where near a billion... optimization is looking good right now....
Add Comment