2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
20
Task/Count-in-factors/Clojure/count-in-factors.clj
Normal file
20
Task/Count-in-factors/Clojure/count-in-factors.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(ns listfactors
|
||||
(:gen-class))
|
||||
|
||||
(defn factors
|
||||
"Return a list of factors of N."
|
||||
([n]
|
||||
(factors n 2 ()))
|
||||
([n k acc]
|
||||
(cond
|
||||
(= n 1) (if (empty? acc)
|
||||
[n]
|
||||
(sort acc))
|
||||
(>= k n) (if (empty? acc)
|
||||
[n]
|
||||
(sort (cons n acc)))
|
||||
(= 0 (rem n k)) (recur (quot n k) k (cons k acc))
|
||||
:else (recur n (inc k) acc))))
|
||||
|
||||
(doseq [q (range 1 26)]
|
||||
(println q " = " (clojure.string/join " x "(factors q))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue