Created
January 18, 2012 00:52
-
-
Save scottlowe/1630087 to your computer and use it in GitHub Desktop.
Project Euler problem 3
This file contains 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
(defn next-factor [target candidate] | |
(if (= 0 (mod target candidate)) | |
candidate | |
(recur target (inc candidate)))) | |
(defn largest-factor [n] | |
(loop [primes [(next-factor n 2)]] | |
(if (= n (reduce * primes)) | |
(last primes) | |
(recur (conj primes (next-factor n (inc (last primes)))))))) | |
(largest-factor 600851475143) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment