【发布时间】:2010-06-03 15:20:21
【问题描述】:
我对这个problem 的回答感觉太像这些solutions in C。
有没有人有什么建议可以让这个更简洁?
(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)))
【问题讨论】:
标签: clojure pythagorean