Factor-perfect numbers: Difference between revisions
m
small speedup, now finishes overnight
(→{{header|Wren}}: Now uses Phix's approach for last part - considerable speed-up.) |
m (small speedup, now finishes overnight) |
||
Line 51:
end
""" Uses the first definition and recursion to count the sequences with less memory usage """
listing = sort!(push!(more_multiples([1], factors(48)[begin:end-1]), [1, 48]))▼
function count_multiples(to_seq, from_seq)
onemores = [[to_seq; i] for i in from_seq if i > to_seq[end] && i % to_seq[end] == 0]
isempty(onemores) && return 0
return length(onemores) + sum(count_multiples(seq, from_seq) for seq in onemores)
end
factorization_counts(n) = count_multiples([1], factors(n)[begin+1:end-1]) + 1 # + 1 for [1, n]
▲listing = sort!(push!(map(a -> push!(a, 48), more_multiples([1], factors(48)[begin+1:end-1])), [1, 48]))
println("48 sequences using first definition:")
for (i, seq) in enumerate(listing)
print(rpad(seq,
end
println("\n48 sequences using second definition:")
for (i, seq) in enumerate(listing)
seq2 = [seq[
print(rpad(seq2, 20), i % 4 == 0 ? "\n" : "")
end
▲""" Get factorization sequence count """
println("\nOEIS A163272: ")
for n in 0:2_400_000
if n == 0 || factorization_counts(n) == n
print(n, ", ")
end
Line 76 ⟶ 83:
<pre>
48 sequences using first definition:
[1, 2
[1, 2, 4,
[1, 2,
[1, 2,
[1, 2, 12, 48]
[1, 3
[1, 3,
[1, 4
[1, 4, 12, 48]
[1, 6
[1, 8
[1, 12,
48 sequences using second definition:
[2,
[
[2, 3, 2,
[2
[2, 6, 4] [2,
[3,
[3,
[4,
[4, 3, 4] [4,
[6,
[8,
[12,
OEIS A163272:
0, 1, 48, 1280, 2496, 28672, 29808, 454656, 2342912,
</pre>
=={{header|Phix}}==
|