Skip to content

Instantly share code, notes, and snippets.

@kohyama
Last active May 18, 2022 02:20
Show Gist options
  • Save kohyama/5b47be8255c1eb859f16 to your computer and use it in GitHub Desktop.
Save kohyama/5b47be8255c1eb859f16 to your computer and use it in GitHub Desktop.

Revisions

  1. kohyama revised this gist Sep 29, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions factorize.clj
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    (defn factorize [n]
    (if-not (< 1 n) '()
    (let [p (first (drop-while #(pos? (mod n %)) prime-numbers))]
    (if (= p n) `(~n)
    (cons p (lazy-seq (factorize (quot n p))))))))
    ((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)))
  2. kohyama created this gist Sep 29, 2015.
    5 changes: 5 additions & 0 deletions factorize.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    (defn factorize [n]
    (if-not (< 1 n) '()
    (let [p (first (drop-while #(pos? (mod n %)) prime-numbers))]
    (if (= p n) `(~n)
    (cons p (lazy-seq (factorize (quot n p))))))))