This problem uses a lot of the helper functions we have defined previously. The major changes are:
- We define a “primes” method that returns an array of all primes than that self.
- We allow a pre-processed list to be passed to prime? which allow us to speed up prime checking.
Perhaps the most interesting aspect to this problem is that I was not able to get it to return an answer superfast without making the algorithm complicated (and un-elegant). But the answer is returned in less than 2 minutes which isn’t bad. But if you run this same code on Ruby 1.9 it returns in a mear 14 seconds. Gives a good indication of the speed improvements we might get moving code to Ruby 1.9.
Also lets me know that even though my algorithm isn’t super-fast it still isn’t bad as we could take the same process and move it to another language like C. It would of course become ugly but