java functions, like Math/sqrt will kill the performance on 4clojure
replace (+ 1 (int (Math/sqrt n))) with n and it will work
Am Donnerstag, 4. Oktober 2012 19:17:05 UTC+2 schrieb Jim Altieri:
> Hey folks,
> I know my solution is probably not the best, but it executes on my machine
> pretty quickly. Am I doing anything obviously wrong?
> (fn [x] (let [prime? (fn [n] (if (= 2 n)
> true
> (not-any? #(zero? (rem n %)) (concat '(2)
> (range 3 (+ 1 (int (Math/sqrt n))))))))
> nextprime (fn [n] (if (= 2 n)
> 3
> (some #(if (prime? %) %) (iterate
> (partial + 2) (+ n 2)))))]
> (if (>= x 5)
> (if (prime? x)
> (let [prev (do (- x (- (nextprime x) x)))]
> (and (prime? prev) (= (nextprime prev) x)))
> false)
> false)))