Primes - allocate descendants to their ancestors: Difference between revisions

Content deleted Content added
Giacomo (talk | contribs)
Giacomo (talk | contribs)
Line 1,414:
using Printf
function ancestraldecendantsprimeAncestorsDecendants(maxsum)
aprimes = primes(maxsum)
ancestors = [Vector{Int}() for _ in 1:maxsum]
Line 1,427:
foreach(p -> pop!(descendants[p]), [aprimes..., 4])
total = 0
format(v::Vector{Int}) = join([dot(n) for n in v], ", ")
dot(n::Int) = replace(string(n), r"(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9]))" => ".")
for s in 1:maxsum
ance = [ancestors[s]..., s]
desc = sort!(descendants[s]); total += dlen = length(desc)
foreach(d-> ancestors[d] = ance,
desc[1:(i-> i==nothing ? 0 : i)(findlast(e-> e<=maxsum, desc))]
)
(s in [0:20..., 46, 74, 99]) || continue
ance = ancestors[s]; alen = length(ance)
@printf("%3d: %1d ancestors %-17s %5d6s descendants %s\n"
, s
, alen, alen==0 ? "" : ance
, dot(dlen), dlen==0 ? ""
: dlen<11 ? desc
: "[$(joinformat(desc[1:5], ", ")), ..., $(joinformat(desc[end-2:end], ", "))]"
)
end
Line 1,446 ⟶ 1,448:
end
ancestraldecendantsprimeAncestorsDecendants(99)</lang>
{{output}}
<pre>
1: 0 ancestors 0 descendants
2: 0 ancestors 0 descendants
3: 0 ancestors 0 descendants
4: 0 ancestors 0 descendants
5: 0 ancestors 1 descendants [6]
6: 1 ancestors [5] 2 descendants [8, 9]
7: 0 ancestors 2 descendants [10, 12]
8: 2 ancestors [5, 6] 3 descendants [15, 16, 18]
9: 2 ancestors [5, 6] 4 descendants [14, 20, 24, 27]
10: 1 ancestors [7] 5 descendants [21, 25, 30, 32, 36]
11: 0 ancestors 5 descendants [28, 40, 45, 48, 54]
12: 1 ancestors [7] 7 descendants [35, 42, 50, 60, 64, 72, 81]
13: 0 ancestors 8 descendants [22, 56, 63, 75, 80, 90, 96, 108]
14: 3 ancestors [5, 6, 9] 10 descendants [33, 49, 70, 84, 100, 120, 128, 135, 144, 162]
15: 3 ancestors [5, 6, 8] 12 descendants [26, 44, 105, 112, 125, ..., 192, 216, 243]
16: 3 ancestors [5, 6, 8] 14 descendants [39, 55, 66, 98, 140, ..., 270, 288, 324]
17: 0 ancestors 16 descendants [52, 88, 99, 147, 175, ..., 405, 432, 486]
18: 3 ancestors [5, 6, 8] 19 descendants [65, 77, 78, 110, 132, ..., 576, 648, 729]
19: 0 ancestors 22 descendants [34, 104, 117, 165, 176, ..., 810, 864, 972]
20: 3 ancestors [5, 6, 9] 26 descendants [51, 91, 130, 154, 156, ..., 12151.215, 12961.296, 14581.458]
46: 3 ancestors [7, 10, 25] 557 descendants [129, 205, 246, 493, 518, ..., 1594323015.943.230, 1700611217.006.112, 1913187619.131.876]
74: 5 ancestors [5, 6, 8, 16, 39] 63366.336 descendants [213, 469, 670, 793, 804, ..., 470715894135470.715.894.135, 502096953744502.096.953.744, 564859072962564.859.072.962]
99: 1 ancestors [17] 3825738.257 descendants [194, 18691.869, 22252.225, 26702.670, 28482.848, ..., 43923441513525124.392.344.151.352.512, 49413871702715764.941.387.170.271.576, 55590605665555235.559.060.566.555.523]
 
Total descendants: 546986546.986
</pre>