Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- frey@garden:~/lein$ cat euler003.clj
- #!/usr/bin/clojure
- (defn divisible? [a b] (= 0 (mod a b)))
- (defn sqrt-rounded-up [x] (inc (int (Math/sqrt x))))
- (defn potential-divisors [n] (range (sqrt-rounded-up n) 1 -1))
- (defn divisors [n] (filter (fn [x] (divisible? n x)) (potential-divisors n)))
- (defn vector-or [coll] (reduce (fn [a b] (or a b)) false coll))
- (defn divisible-by-any? [n divisors] (vector-or (map (fn [divisor] (divisible? n divisor)) divisors)))
- (defn prime? [n] (not (divisible-by-any? n (potential-divisors n))))
- (println (apply max (filter prime? (divisors 600851475143))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement