Category talk:Wren-math: Difference between revisions
→Source code: Improved algorithm for Int.divisors2.
(Added efficient divisorSum, divisorCount and reverse methods to Int class.) |
(→Source code: Improved algorithm for Int.divisors2.) |
||
Line 632:
// As 'divisors' method but uses a different algorithm.
// Better for
static divisors2(n) {
var
} else {
var prevPrime = pf[0]
var count = 1
for (i in 1...pf.count) {
if (pf[i] == prevPrime) {
count = count + 1
} else {
arr.add([prevPrime, count])
prevPrime = pf[i]
count = 1
}
}
arr.add([prevPrime, count])
}
var
return
}
for (i in 0..arr[currIndex][1]) {
generateDivs.call(currIndex+1, currDivisor)
currDivisor = currDivisor * arr[currIndex][0]
}
}
return divisors.sort()
}
|