[seqfan] Re: %N A028387 Numbers of form n+(n+1)^2 (?)

Peter Pein petsie at dordos.net
Sat Jul 3 19:03:44 CEST 2010


Am Sat, 3 Jul 2010 06:32:29 -0700 (PDT)
schrieb zak seidov <zakseidov at yahoo.com>:

> Why not simply a(n)=n+(n+1)^2 (?).
> Zak
> 
> 
> 
>       
> 
> _______________________________________________
> 
> Seqfan Mailing list - http://list.seqfan.eu/
I agree it should read _all_ numbers of form n + (n+1)^2 or what you
suggested.

 And I do not understand why the (last) Mma-Program is so
complicated:

s = 1; lst = {s}; Do[s += n + 3; AppendTo[lst, s], {n, 1, 100, 2}]; lst
instead of 
FoldList[Plus[##, 3] &, 1, Range[1, 99, 2]] (without side-effects)
(and it is ~1200 times faster (for 27162 elements))

Peter

P.S.:
In[10]:=
s=1;lst={s};Do[s+=n+3;AppendTo[lst,s],{n,1,54321,2}];lst;//Timing
Out[10]= {36.39,Null}
 In[11]:=
lst2=FoldList[Plus[##,3]&,1,Range[1,54321,2]];//Timing Out[11]=
{0.03,Null}
In[12]:= lst===lst2
Out[12]= True
In[13]:= 36.39/0.03
Out[13]= 1213.
In[14]:= Length[lst]
Out[14]= 27162




More information about the SeqFan mailing list