Created
September 9, 2009 18:24
-
-
Save fogus/183941 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
;; 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)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment