(defn happy-numers? [num] (letfn [(squrt [n] (reduce #(+ %1 (* %2 %2)) 0 (map #(Integer/valueOf (str %)) (str n)))) (fn1 [n results] (let [r (squrt n)] (cond (= 1 r) true (results r) false :else (recur r (conj results r)))))] (fn1 num #{})))
本文共 379 字,大约阅读时间需要 1 分钟。
(defn happy-numers? [num] (letfn [(squrt [n] (reduce #(+ %1 (* %2 %2)) 0 (map #(Integer/valueOf (str %)) (str n)))) (fn1 [n results] (let [r (squrt n)] (cond (= 1 r) true (results r) false :else (recur r (conj results r)))))] (fn1 num #{})))
转载于:https://my.oschina.net/diqye/blog/528648