Sep. 17th, 2015

orleanz: (main)
Взял, чисто навскидку, первую, тривиальную задачу с Проект Эйлера

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))


Понятно что ее можно написать в одну строчку, но этому мы потом научимся.

Главное почин.

Profile

orleanz: (Default)
orleanz

December 2018

S M T W T F S
      1
2345678
9101112 131415
16171819202122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 23rd, 2025 07:39 pm
Powered by Dreamwidth Studios