Skip to content

Instantly share code, notes, and snippets.

@kohyama
Last active May 18, 2022 02:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohyama/5b47be8255c1eb859f16 to your computer and use it in GitHub Desktop.
Save kohyama/5b47be8255c1eb859f16 to your computer and use it in GitHub Desktop.
Prime Factorization in Clojure
(defn factorize [n]
((fn f [n [h & r :as ps]]
(cond (< n 2) '()
(zero? (mod n h)) (cons h (lazy-seq (f (quot n h) ps)))
:else (recur n r)))
n prime-numbers)))
@kohyama
Copy link
Author

kohyama commented Sep 29, 2015

Assumed that prime-numbers is defined by
https://gist.github.com/kohyama/8e599b2e765ad4256f32

Example To Use:

user=> (take 10 prime-numbers)
(2 3 5 7 11 13 17 19 23 29)
user=> (apply * *1)
6469693230
user=> (factorize *1)
(2 3 5 7 11 13 17 19 23 29)
user=> (#(*' % % % %) *2)
1752002630070461520695765003094322410000N
user=> (factorize *1)
(2 2 2 2 3 3 3 3 5 5 5 5 7 7 7 7 11 11 11 11 13 13 13 13 17 17 17 17 19 19 19 19 23 23 23 23 29 29 29 29)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment