Count in factors: Difference between revisions

Added Wren
m (→‎{{header|Raku}}: Fix-up some Perl6 -> Raku references)
(Added Wren)
Line 4,151:
57096 = 2 * 2 * 2 * 3 * 3 * 13 * 61
57097 = 57097
</pre>
 
=={{header|Wren}}==
<lang ecmascript>var primeFactors = Fn.new { |n|
if (n == 1) return [1]
var factors = []
while (n % 2 == 0) {
factors.add(2)
n = n / 2
}
var i = 3
var lim = n.sqrt.floor
while (i <= lim) {
while (n % i == 0) {
factors.add(i)
n = n / i
}
i = i + 2
}
if (n > 2) factors.add(n)
return factors
}
 
for (r in [1..9, 2144..2154, 9987..9999]) {
for (i in r) System.print("%(i): %(primeFactors.call(i).join(" x "))")
System.print()
}</lang>
 
{{out}}
<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
 
2144: 2 x 2 x 2 x 2 x 2 x 67
2145: 3 x 5 x 11 x 13
2146: 2 x 29 x 37
2147: 19 x 113
2148: 2 x 2 x 3 x 179
2149: 7 x 307
2150: 2 x 5 x 5 x 43
2151: 3 x 3 x 239
2152: 2 x 2 x 2 x 269
2153: 2153
2154: 2 x 3 x 359
 
9987: 3 x 3329
9988: 2 x 2 x 11 x 227
9989: 7 x 1427
9990: 2 x 3 x 3 x 3 x 5 x 37
9991: 97 x 103
9992: 2 x 2 x 2 x 1249
9993: 3 x 3331
9994: 2 x 19 x 263
9995: 5 x 1999
9996: 2 x 2 x 3 x 7 x 7 x 17
9997: 13 x 769
9998: 2 x 4999
9999: 3 x 3 x 11 x 101
</pre>
 
9,485

edits