Attractive numbers: Difference between revisions

Content deleted Content added
PureFox (talk | contribs)
→‎{{header|Wren}}: Library name change.
PureFox (talk | contribs)
→‎{{header|Wren}}: Now uses Wren-math module.
Line 2,782:
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<lang ecmascript>import "/fmt" for Fmt
import "/math" for Int
 
var isPrime = Fn.new { |n|
if (n < 2 || !n.isInteger) return false
if (n%2 == 0) return n == 2
if (n%3 == 0) return n == 3
var d = 5
while (d*d <= n) {
if (n%d == 0) return false
d = d + 2
if (n%d == 0) return false
d = d + 4
}
return true
}
 
var countPrimeFactors = Fn.new { |n|
if (n == 1) return 0
if (isPrime.call(n)) return 1
var count = 0
var f = 2
while (true) {
if (n%f == 0) {
count = count + 1
n = (n/f).floor
if (n == 1) return count
if (isPrime.call(n)) f = n
} else if (f >= 3) {
f = f + 2
} else {
f = 3
}
}
return count
}
 
var max = 120
System.print("The attractive numbers up to and including %(max) are:")
var count = 0
for (i in 1..max) {
var n = countPrimeFactorsInt.callprimeFactors(i).count
if (isPrimeInt.callisPrime(n)) {
System.write(Fmt.d(4, i))
count = count + 1