Self numbers: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added escuse) |
m (→generator dictionary: pqhead -> gdhead) |
||
Line 612: | Line 612: | ||
Aside: the getd_index() check is often worth trying with phix dictionaries: if there is a high probability that |
Aside: the getd_index() check is often worth trying with phix dictionaries: if there is a high probability that |
||
the key already exists, it will yield a win, but with a low probability it will just be unhelpful overhead. |
the key already exists, it will yield a win, but with a low probability it will just be unhelpful overhead. |
||
<lang Phix>integer gd = new_dict(), g = 1, |
<lang Phix>integer gd = new_dict(), g = 1, gdhead = 2, n = 0 |
||
function ng(integer n) |
function ng(integer n) |
||
Line 627: | Line 627: | ||
integer nxt |
integer nxt |
||
n += 1 |
n += 1 |
||
while n= |
while n=gdhead do |
||
while g<= |
while g<=gdhead do |
||
nxt = ng(g) |
nxt = ng(g) |
||
if getd_index(nxt, gd)=NULL then -- (~25% gain) |
if getd_index(nxt, gd)=NULL then -- (~25% gain) |
||
Line 635: | Line 635: | ||
g += 1 |
g += 1 |
||
end while |
end while |
||
integer |
integer wasgdhead = gdhead |
||
while true do |
while true do |
||
gdhead = pop_dict(gd)[1] |
|||
if |
if gdhead!=wasgdhead then exit end if |
||
-- ?{"ding", |
-- ?{"ding",wasgdhead} -- 2, once only... |
||
end while |
end while |
||
nxt = ng( |
nxt = ng(gdhead) |
||
-- if getd_index(nxt, gd)=NULL then -- (~1% loss) |
-- if getd_index(nxt, gd)=NULL then -- (~1% loss) |
||
setd(nxt,0,gd) |
setd(nxt,0,gd) |
||
-- end if |
-- end if |
||
n += (n!= |
n += (n!=gdhead) |
||
end while |
end while |
||
return n |
return n |