-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path45.clj
34 lines (29 loc) · 808 Bytes
/
45.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(def triangles
(map #(/ (* %
(inc %))
2)
(iterate inc 1)))
(def pentagonals
(map #(/ (* %
(- (* 3 %) 1))
2)
(iterate inc 1)))
(def hexagonals
(map #(* %
(- (* 2 %) 1))
(iterate inc 1)))
(defn incsmallest [somevec]
(def smallest (apply min (map first somevec)))
(map #(if (= (first %)
smallest)
(next %)
(identity %))
somevec))
(def results
(map ffirst
(filter #(= (first (nth % 0))
(first (nth % 1))
(first (nth % 2)))
(iterate incsmallest
[triangles pentagonals hexagonals]))))
(time (println (take 1 (drop-while #(< % 40756) results))))