6
我對這個problem的答案感覺太像這些solutions in C。項目歐拉#9(畢達哥拉斯三胞胎)在Clojure
有沒有人有任何建議,使這更lispy?
(use 'clojure.test)
(:import 'java.lang.Math)
(with-test
(defn find-triplet-product
([target] (find-triplet-product 1 1 target))
([a b target]
(let [c (Math/sqrt (+ (* a a) (* b b)))]
(let [sum (+ a b c)]
(cond
(> a target) "ERROR"
(= sum target) (reduce * (list a b (int c)))
(> sum target) (recur (inc a) 1 target)
(< sum target) (recur a (inc b) target))))))
(is (= (find-triplet-product 1000) 31875000)))
大資源...感謝。 – dbyrne 2010-06-03 15:33:05
+1鏈接! – 2010-06-04 14:17:37