Count in factors: Difference between revisions

Content added Content deleted
(Added Maple implementation.)
Line 495: Line 495:
}
}
}</lang>
}</lang>

=={{header|Clojure}}==
<lang lisp>(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))))
</lang>
{{Output}}
<pre>
1 = 1
2 = 2
3 = 3
4 = 2 x 2
5 = 5
6 = 2 x 3
7 = 7
8 = 2 x 2 x 2
9 = 3 x 3
10 = 2 x 5
11 = 11
12 = 2 x 2 x 3
13 = 13
14 = 2 x 7
15 = 3 x 5
16 = 2 x 2 x 2 x 2
17 = 17
18 = 2 x 3 x 3
19 = 19
20 = 2 x 2 x 5
21 = 3 x 7
22 = 2 x 11
23 = 23
24 = 2 x 2 x 2 x 3
25 = 5 x 5
</pre>


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==