Factor-perfect numbers: Difference between revisions

→‎{{header|Wren}}: Changed to Erdos method for factor counting - another huge speed-up > 30x.
(→‎{{header|Wren}}: Changed to Erdos method for factor counting - another huge speed-up > 30x.)
Line 317:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
Timings are about: 0.19 secs for 7, 8.5 secs for 8 and 97 secs for 9 factor-perfect numbers.
However, using Phix's 'g' function for the last part which is considerably quicker than generating a bunch of lists and then counting them - overall time down from 76 to 7 seconds. Still not really worth attempting stretch goal though.
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./fmt" for Fmt
Line 335:
}
 
var cache = {}
// Get factorization sequence count.
 
var countMultipleSequences = Fn.new { |n|
var erdosFactorCount
var f = Int.properDivisors(n)
erdosFactorCount = Fn.new { |n|
f.removeAt(0)
var ldivs = fInt.countproperDivisors(n)
var d = Listdivs.filledremoveAt(l, 0)
forvar (isum in= l-1..0) {
for (d in divs) var k = f[i]{
d[i]var t = 1(n/d).floor
if (!cache.containsKey(t)) cache[t] = erdosFactorCount.call(t)
var j = i + 1
var xsum = 2sum *+ kcache[t]
while (x <= n) {
while (j < l && f[j] < x) j = j + 1
if (j > l-1) break
if (f[j] == x) d[i] = d[i] + d[j]
x = x + k
}
}
return 1sum + Nums.sum(d)1
}
 
Line 385 ⟶ 379:
var n = 4
var fpns = [0, 1]
while (fpns.count < 79) {
if (countMultipleSequenceserdosFactorCount.call(n) == n) fpns.add(n)
n = n + 4
}
Line 405 ⟶ 399:
[1, 6, 48] [1, 6, 12, 48] [1, 6, 12, 24, 48] [1, 6, 24, 48]
[1, 8, 48] [1, 8, 16, 48] [1, 8, 24, 48] [1, 12, 48]
[1, 12, 24, 48] [1, 16, 48] [1, 24, 48] [1, 48]
 
48 sequences using second definition:
[2, 24] [2, 2, 12] [2, 2, 2, 6] [2, 2, 2, 2, 3]
Line 422 ⟶ 416:
 
OEIS A163272:
[0, 1, 48, 1280, 2496, 28672, 29808, 454656, 2342912]
</pre>
9,488

edits