;; 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.

(defn multiple-of-3-or-5? 
  [n]
  (if (or (zero? (rem n 3))
	  (zero? (rem n 5)))
    n
    0))

(defn euler-1-v0 [n]
  "Sum of all the multiples of 3 and 5 below n"
  (reduce + (map multiple-of-3-or-5? (range 0 n))))

(defn euler-1-v1 [n]
  "Sum of all the multiples of 3 and 5 below n"
  (reduce + (filter #(or (zero? (rem % 3))
			 (zero? (rem % 5))) (range 0 1000))))

 
projecteuler/problem1.txt · Last modified: 2009/11/07 07:23 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki