John Duncan on Fri, 02 Sep 2022 22:47:40 +0200


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

Re: setsearch()


Dear Aurel,

Oh, I see. Thank you!

Best,


John

On Sat, Sep 3, 2022 at 4:41 AM Aurel Page <aurel.page@normalesup.org> wrote:
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;
}