I am trying to solve Project Euler problem in Clojure using recursion. The following is the problem statement:
If we list all the natural numbers below 10 that are multiples of 3 or
5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000.
However, the code below seems to give the wrong answer. What am I doing wrong?
(defn m?
[x]
(or (= (rem x 3)) (= (rem x 5))))
(defn sum-m
[limit sum]
(if (= limit 0)
sum
(recur (dec limit)
(if (m? limit)
(+ sum limit)
sum))))
(sum-m (dec 1000) 0)
You didn’t say what erroneous answer it was giving, but I believe the problem is in m?: