Написал первую в жизни программу на Кложе
Sep. 17th, 2015 03:10 pmВзял, чисто навскидку, первую, тривиальную задачу с Проект Эйлера
Multiples of 3 and 5
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.
Понятно что ее можно написать в одну строчку, но этому мы потом научимся.
Главное почин.
Multiples of 3 and 5
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.
(def my-range (range 1 1000)) (defn mult-of-3 [x] (= 0 (rem x 3)) ) (defn mult-of-5 [x] (= 0 (rem x 5)) ) (defn predicate [x] (or (mult-of-3 x) (mult-of-5 x) )) (reduce + (filter predicate my-range))
Понятно что ее можно написать в одну строчку, но этому мы потом научимся.
Главное почин.