### re: Project Euler #1 - Multiples of 3 and 5 VIEW POST

At last count I did that exercise in 11 different languages, so maybe I'll post some of the less common ones.

Clojure:

``````(defn problem1
[n]
(reduce + (filter #(or (= 0 (mod % 3)) (= 0 (mod % 5))) (range 1 n))))

(println (problem1 1000))
``````

``````main :: IO ()
main = print problem1

problem1 :: Integer
problem1 = sum (filter (\x -> x `mod` 3 == 0 || x `mod` 5 == 0) [1..999])
``````

Haskell (a bit more interesting, but wasteful):

``````import Data.List
problem1 = sum \$ nub \$ [3,6..999] ++ [5,10..999]
``````
``````Number dividesBy = (x):
self % x == 0.

sum = 0
1 to 999 (x):
if (x dividesBy(3) || x dividesBy(5)): sum += x
_x
(sum, "\n") join print
``````

GNU Smalltalk:

``````res := ((3 to: 999) select: [:i| (i \\ 3 = 0) | (i \\ 5 = 0)])
inject: 0 into: [:sum :i| sum+i].
res printNl
``````

Here's one in Haskell using list comprehension:

``````sum [x | x <- [1..999], x `mod` 3 == 0 || x `mod` 5 == 0]
``````
code of conduct - report abuse