Because every non-prime number is divisible by at least one prime number, so I figured I could save a lot of iterations by storing the numbers I knew to be prime and only checking new numbers against those.
(I actually don't know if I knew that about prime numbers at some point and had forgotten it, but I spent quite a few minutes going, "Wait, is that true? I think it might be! Let's see if it works.")
Also, I've been writing a lot of Ruby on Rails code, and it's possible I'm just used to using arrays for everything. :)
no subject
(I actually don't know if I knew that about prime numbers at some point and had forgotten it, but I spent quite a few minutes going, "Wait, is that true? I think it might be! Let's see if it works.")
Also, I've been writing a lot of Ruby on Rails code, and it's possible I'm just used to using arrays for everything. :)