in Programming

Project Euler Problem 10 Solution: Clojure

Problem description, from Project Euler

Find the sum of all the primes below N.

Solution

Brute-forced it again, but it still runs in less than 30 seconds (at least on my MacBook Pro). This one was simple using the Sieve of Eratosthenes from problem 7.

The sieve, collapsed because it’s the same as from problem 7:

The new code:
1
2
3
(defn problem10 [max-nbr]
    (reduce + (sieve-of-eratosthenes max-nbr)) ; brute!
    )

Comments are closed.