Created
May 7, 2010 08:58
-
-
Save pbadenski/393212 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
(with-test | |
(defn prime-factors [n] | |
((fn this [n_ last-divisor] | |
(if (= n_ 1) | |
[] | |
(let [ | |
divisor | |
(or | |
(some | |
#(when (zero? (mod n_ %)) %) | |
(range last-divisor (. Math sqrt n))) | |
n_)] | |
(cons | |
divisor | |
(this (/ n_ divisor) last-divisor))))) | |
n 2)) | |
(are (= (prime-factors _1) _2) | |
1 [] | |
2 [2] | |
3 [3] | |
4 [2 2] | |
5 [5] | |
6 [2 3] | |
7 [7] | |
8 [2 2 2] | |
(dec (** 2 17)) [(dec (** 2 17))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment