MathGroup Archive 2006

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

Search the Archive

Re: Re: Finding the Number of Pythagorean Triples below a bound


On 4 Aug 2006, at 09:59, titus_piezas at yahoo.com wrote:

> Hello Andrzej,
>
> The code I used was this:
>
> c1=Sqrt[N[a^2+b^2-k]];
>
> countTriples[m_]:=Block[{a,b,i=0},For[a=1,a<(10^m/Sqrt[2]),a++,
> For[b=a,b<10^m,b++,If[c1==Round[c1]&&c1<10^m,i++]]];i]
>
> though m=3 takes about 50 sec (in an old comp) while m=4 will  
> prolly be
>
> around 5000 sec (83 mins).
>
>
> -Titus
>


This is very odd indeed. For example, I get:


c1=Sqrt[N[a^2+b^2-k]];


countTriples[m_]:=Block[{a,b,i=0},For[a=1,a<(10^m/Sqrt[2]),a++,
For[b=a,b<10^m,b++,If[c1==Round[c1]&&c1<10^m,i++]]];i]

In[6]:=
k=3;


countTriples[2]

Invalid comparison
     with  0. I attempted.

13

The correct answer is:


f[10^2,-3]


28


Similarly for other values. Your code usually doesn't work on my  
machine and when it does it produces wrong answers.

Andrzej Kozlowski


  • Prev by Date: RE: Converting Mathematics slides into PDF
  • Next by Date: RE: Change CellTags with FrontEnd
  • Previous by thread: Re: Finding the Number of Pythagorean Triples below a bound
  • Next by thread: Re: Re: Finding the Number of Pythagorean Triples below a bound