| Ruud H.G. van Tol on Mon, 12 Jan 2026 23:31:15 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: fibint(n), fibbinary(n) |
On 2026-01-11 23:15, Ruud H.G. van Tol wrote:
On 2026-01-11 18:18, Bill Allombert wrote: > On Sun, Jan 11, 2026 at 05:45:42PM +0100, Ruud H.G. van Tol wrote:>> I'm looking for an effective (discrete, loop-less) way to derive the n-th>> fibbinary number (Zeckendorf representation). >> For definitions, see https://oeis.org/A003714. >> >> [ n | n<-[0..100], !bitand(n,n>>1) ] >> [0, >> 1, >> 2, >> 4, 5, >> 8, 9, 10, >> 16, 17, 18, 20, 21, >> 32, 33, 34, 36, 37, 40, 41, 42, >> 64, 65, 66, 68, 69, 72, 73, 74, 80, 81, 82, 84, 85 >> ] [...]
A pretty straight way to generate the sequence as a list:
upto(lim)= {
my( r=List([0]), t );
for( i=1, oo
, (t=r[i]<<1) <= lim || break;
t && listput(~r, t);
bitand(t, 2) || listput(~r, t++)
);
Vec(r);
}
That does about 1.4M terms per second.
(and it deliberately overshoots by one if lim == 0 (mod 4) is a term)
-- Ruud