Thank you for your patience as you all (I'm sure) anxiously await my next posting.
Not only has it been a really long time since I posted something technical, it's also been a really long time since I posted a Project Euler solution. On that note, let's go over the challenge:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Seems simple enough doesn't it? Let's find out. For Python the code is:
- Python based code solution to problem 10 of project euler.
- import math
- def is_prime(divided):
- divisor = 3
- sqrt_divided = int(math.sqrt(divided))
- while divisor <= sqrt_divided:
- if divided % divisor == 0:
- return False
- divisor += 2
- return True
- if __name__ == "__main__":
- print sum( + [x for x in xrange(3,2000000+1, +2) if is_prime(x)])
And for Haskell the code looks like:
Even though you and I know that Haskell will execute this code faster than Python, I feel I still need to uphold the tradition of posting my highly inaccurate execution times: