-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path074.clj
More file actions
26 lines (20 loc) · 680 Bytes
/
074.clj
File metadata and controls
26 lines (20 loc) · 680 Bytes
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
(defn factorial [x]
(apply * (range 2 (inc x))))
(def fact-map
(apply hash-map (interleave (seq "0123456789")
(map #(factorial %) (range 10)))))
(defn next-number [n]
(reduce + (map #(fact-map %) (str n))))
(def next-memo (memoize next-number))
(defn cycle-length [n_]
(let [accum []]
(loop [n n_, coll accum ]
(let [next-coll (conj coll n)
next-n (next-memo n)]
(if (some #(= next-n %) next-coll)
(count next-coll)
(recur next-n next-coll))))))
(defn euler074 []
(count (filter #(= 60 %) (pmap cycle-length (range 1 1000000)))))
(time (println (euler074)))
(shutdown-agents)