Skip to content

Instantly share code, notes, and snippets.

@scottlowe
Created January 18, 2012 00:52
Show Gist options
  • Save scottlowe/1630087 to your computer and use it in GitHub Desktop.
Save scottlowe/1630087 to your computer and use it in GitHub Desktop.
Project Euler problem 3
(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