#### Description

From Project Euler:The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

#### Solution

As you'll recall, back in problem 7 we created a general purpose prime number generator. That is going to come in extremely handy for this problem. Why? Well, the solution is as easy as:PrimeGenerator.new.take_while { |p| p < 2_000_000 }.reduce(:+)And that is all there is to it. Now wasn't that simple?

The full source and specifications can be seen on github. Next time, finding the greatest product of four numbers on the same line in a 20x20 grid.

## No comments:

Post a Comment