Created
January 3, 2014 12:53
-
-
Save knjname/8237449 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def sqrt [n] | |
| (Math/sqrt n)) | |
| (defn find-max-factor [n] | |
| (let [max-range (long (Math/ceil (sqrt n)))] | |
| (loop [i max-range] | |
| (if (= 0 (mod n i)) | |
| (max i (/ n i)) | |
| (recur (- i 1)))))) | |
| (defn find-factors | |
| ([n] | |
| (find-factors n 2N [])) | |
| ([n divisor factors] | |
| (if (<= divisor n) | |
| (if (= 0 (mod n divisor)) | |
| (recur (long (/ n divisor)) divisor (conj factors divisor)) | |
| (recur n (+ divisor 1N) factors)) | |
| factors))) | |
| (println (apply max (find-factors 600851475143N))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment