;; largest prime factor
(defn lpf
"Takes a number n and a starting number d > 1
and calculates the largest prime factor of n
starting at number d.
usage: (lpf 364362978 2) => 8675309"
[n d]
(if (> d n)
(- d 1)
(recur
(#(if (zero? (rem % d))
(recur (/ % d))
%)
n)
(inc d))))
This is the smallest `lpf` that I could come up with -- can you do
better? Can you make it faster (shouldn't be too hard, considering
mine is atrociously slow)?
More information at:
http://blog.fogus.me/2009/09/09/clojure-golf-episode-2-largest-prime-factor/
Have at it!
-m