I’m back again with another post in my Yet Another Project Euler Series. As a reminder, my approach to these problems is to try to find the most beautiful solution that I can using F#. While performance is an important, I’m looking for the most elegant solutions that I can find.
Project Euler problem ten is another dealing prime numbers.
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
As you can guess, there’s not too much to this problem. In fact, we’ll declare just one simple supporting function.
let lessThan y x = x < y
Using the above function and our existing prime number generator, our solution is short and simple.
|> Seq.take_while (lessThan 2000000L)
I feel a little guilty that this post is so short, but that’s the benefit of spending two whole blog posts working out a prime number generator for problem seven.