Category talk:Wren-big: Difference between revisions

→‎Source code: Added divisors and properDivisors methods to BigInt.
m (→‎Source code: Added quotes to 'lang' attribute.)
(→‎Source code: Added divisors and properDivisors methods to BigInt.)
Line 1,478:
if (m is Num) m = BigInt.new(m)
return primeFactors_(m, true)
}
 
// Returns all the divisors of 'n' including 1 and 'n' itself.
static divisors(n) {
if (n <= BigInt.zero) return []
var factors = BigInt.primeFactors(n)
var divs = [BigInt.one]
for (p in factors) {
for (i in 0...divs.count) divs.add(divs[i]*p)
}
divs.sort()
var c = divs.count
if (c > 1) {
for (i in c-1..1) {
if (divs[i-1] == divs[i]) divs.removeAt(i)
}
}
return divs
}
 
// Returns all the divisors of 'n' excluding 'n'.
static properDivisors(n) {
var d = divisors(n)
var c = d.count
return (c <= 1) ? [] : d[0..-2]
}
}
9,476

edits