Ruud H.G. van Tol on Tue, 10 Mar 2026 14:06:02 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

increment slowdown



oeis.A005228:

? lista1(len)= my(r=List(1), d=1); while(#r<len, setsearch(r, d++) && d++; listput(~r, r[#r]+d)); Vec(r);

? lista1(10001)[-10..-1]
cpu time = 227 ms, real time = 228 ms.
%7 = [50793733, 50803858, 50813984, 50824111, 50834239, 50844368, 50854498, 50864629, 50874761, 50884894]


? lista2(len)= my(r=List(1), d=1); while(#r<len, d++; setsearch(r, d) && d++; listput(~r, r[#r]+d)); Vec(r);

? lista2(10001)[-10..-1]
cpu time = 18 ms, real time = 18 ms.
%12 = [50793733, 50803858, 50813984, 50824111, 50834239, 50844368, 50854498, 50864629, 50874761, 50884894]


The first variant has the d++ inside the setsearch() call, and is much slower.
Is that a bug?

-- Greetings Ruud