MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How do quickest



Hi Arthur,

Instead of searching for a solution inside the While loop, it is much 

faster ()but a bit more cumbersome to use Reduce. E.g.:

a={3};

For[k=1+a[[Length[a]]],Length[a]<10,

   s2=Sum[(a[[t]])^2,{t,1,Length[a]}]; 

t=Reduce[{y^2+s2\[Equal]x^2,x>0,y>=k},{y,x},Integers][[1]];

   t=t/.{Equal->Rule,And->List};

   k=y/.t;

   AppendTo[a,k]];

a



Artur wrote:

> How do quickest following very slowly procedure:

> a = {3}; For[k = 1 + a[[Length[

>      a]]], Length[a] < 13, While[! IntegerQ[Sqrt[(k)^2 + Sum[(a[[t]])^2,  

> {t, 1,

>     Length[a]}]]], k++]; AppendTo[a, k]]; a

> 

> ARTUR

> 



  • Prev by Date: Re: how to quickly read a >10MB big file
  • Next by Date: Re: How to remove Dot?
  • Previous by thread: How do quickest
  • Next by thread: Re: Re: How do quickest