Created
May 16, 2010 01:34
-
-
Save trptcolin/402575 to your computer and use it in GitHub Desktop.
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
(ns primeFactors) | |
(defn square [n] (* n n)) | |
(defn divisible-by? [n candidate] | |
(= 0 (rem n candidate))) | |
(defn of [n] | |
(loop [factors [] n n candidate 2] | |
(cond | |
(= n 1) factors | |
(divisible-by? n candidate) (recur (conj factors candidate) (/ n candidate) candidate) | |
(> (square candidate) n) (conj factors n) | |
:else (recur factors n (inc candidate))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment