Igor Schein on Thu, 02 Jun 2011 00:55:07 +0200


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

binary() generalization


Hi,

I am looking for an efficient generalization of gp's binary() function.

digits(n,b)=local(m=n,L=List);while(m,v=divrem(m,b);listinsert(L,v[2],1);m=v[1]);

It's very inefficient compared to the native function:

? for(k=10^5,10^6,digits(k,2))
time = 18,749 ms.
? for(k=10^5,10^6,digits(k,10))
time = 6,401 ms.
? for(k=10^5,10^6,binary(k))
time = 236 ms.


Can I do better than that?

Thanks

Igor