Aurel Page on Fri, 02 Sep 2022 22:41:34 +0200


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

Re: setsearch()


Dear John,

setsearch assumes that the vector is sorted. You can achieve this with v = Set(v).

Best,
Aurel

On 02/09/2022 22:35, John Duncan wrote:
Dear all,

I would expect the function copied below to return a vector of zeros of length n, for any n. But it doesn't (for me, running Version 2.13.4), for n>9. Can someone explain to me why? and how to "fix" it?

Faithfully,


John

f(n)=
{
local(v,ans);
v=vector(n,i,Str(i));
ans=vector(n,i,setsearch(v,v[i],1));
ans;
}