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
 
""" Getcount all the factorization sequencesequences countof n """
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, 2022), i % 4 == 0 ? "\n" : "")
end
 
println("\n48 sequences using second definition:")
for (i, seq) in enumerate(listing)
seq2 = [seq[endj] !=÷ 48seq[j &&- push!1] for j in 2:length(seq, 48)]
seq2 = [seq[i] ÷ seq[i - 1] for i in 2:length(seq)]
print(rpad(seq2, 20), i % 4 == 0 ? "\n" : "")
end
 
""" Get factorization sequence count """
count_multiple_sequences(n) = length(more_multiples([1], factors(n)[begin:end-1])) + 1
 
println("\nOEIS A163272: ")
for n in 0:2_400_000
if n % 100000 == 0 ||&& count_multiple_sequencesprint(n), =="\b" ^ ndigits(n))
if n == 0 || factorization_counts(n) == n
print(n, ", ")
end
Line 76 ⟶ 83:
<pre>
48 sequences using first definition:
[1, 2] , 4, 8, 16, 48] [1, 2, 4] , 8, 24, 48] [1, 2, 4, 8, 48] [1, 2, 4, 812, 1624, 48]
[1, 2, 4, 812, 2448] [1, 2, 4, 1216, 48] [1, 2, 4, 1224, 2448] [1, 2, 4, 1648]
[1, 2, 46, 12, 24, 48] [1, 2, 6] , 12, 48] [1, 2, 6, 1224, 48] [1, 2, 6, 12, 2448]
[1, 2, 68, 2416, 48] [1, 2, 8] , 24, 48] [1, 2, 8, 1648] [1, 2, 812, 24, 48]
[1, 2, 12, 48] [1, 2, 1216, 2448] [1, 2, 1624, 48] [1, 2, 2448]
[1, 3] , 6, 12, 24, 48] [1, 3, 6] , 12, 48] [1, 3, 6, 1224, 48] [1, 3, 6, 12, 2448]
[1, 3, 612, 24, 48] [1, 3, 12, 48] [1, 3, 1224, 2448] [1, 3, 2448]
[1, 4] , 8, 16, 48] [1, 4, 8] , 24, 48] [1, 4, 8, 1648] [1, 4, 812, 24, 48]
[1, 4, 12, 48] [1, 4, 1216, 2448] [1, 4, 1624, 48] [1, 4, 2448]
[1, 6] , 12, 24, 48] [1, 6, 12, 48] [1, 6, 1224, 2448] [1, 6, 2448]
[1, 8] , 16, 48] [1, 8, 1624, 48] [1, 8, 2448] [1, 12, 24, 48]
[1, 12, 2448] [1, 16, 48] [1, 24] , 48] [1, 48]
 
48 sequences using second definition:
[2, 24] 2, 2, 2, 3] [2, 2, 12] 2, 3, 2] [2, 2, 2, 6] [2, 2, 23, 2, 32]
[2, 2, 2, 3, 24] [2, 2, 34, 43] [2, 2, 3, 26, 2] [2, 2, 4, 312]
[2, 3, 2, 62, 2] [2, 3, 82, 4] [2, 3, 24, 42] [2, 3, 2, 2, 28]
[2, 3, 4, 2, 3] [2, 4, 63, 2] [2, 4, 2, 36] [2, 46, 32, 2]
[2, 6, 4] [2, 68, 2, 23] [2, 812, 32] [2, 12, 224]
[3, 16] 2, 2, 2, 2] [3, 2, 82, 4] [3, 2, 24, 42] [3, 2, 2, 2, 28]
[3, 24, 42, 2] [3, 4, 4] [3, 4, 28, 2] [3, 8, 216]
[4, 12] 2, 2, 3] [4, 2, 63, 2] [4, 2, 2, 36] [4, 23, 32, 2]
[4, 3, 4] [4, 34, 2, 23] [4, 46, 32] [4, 6, 212]
[6, 8] 2, 2, 2] [6, 2, 4] [6, 2, 24, 2] [6, 4, 28]
[8, 62, 3] [8, 23, 32] [8, 3, 26] [12, 42, 2]
[12, 2, 24] [16, 3] [24, 2] [48]
 
OEIS A163272:
0, 1, 48, 1280, 2496, 28672, 29808, 454656, 2342912,
</pre>
 
 
=={{header|Phix}}==
4,107

edits