Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Math
Message
From
17/05/2008 00:17:56
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
14/05/2008 09:41:50
General information
Forum:
Politics
Category:
Other
Title:
Re: Math
Miscellaneous
Thread ID:
01316946
Message ID:
01317804
Views:
11
>Which natural numbers occur as the area of a right triangle with three rational sides?
>5 is the smallest number that can be used.

Heh, it's been some 25 years since I last wrote code to calculate that :).

You're looking for Pythagorean numbers, i.e. squares which differ from each other by yet another. You may just stuff all the squares up to 32767 into... lemme see.
create cursor crsI (i i)
for xi=3 to 800
	insert into crsI values (xi*xi)
endfor
INDEX ON i TAG i
select a.i as hypo, b.i as cath1, c.i as cath2 ;
	from crsI a, crsI b, crsI c;
	WHERE a.i>b.i AND b.i>c.i AND a.i=b.i+c.i ;
	into cursor crsPythagora

SELECT CAST(SQRT(hypo) as int) as hypo;
	,	CAST(SQRT(cath1) as int) as cath1;
	,	CAST(SQRT(cath2) as int) as cath2;
	FROM crspythagora ;
	INTO CURSOR crsTriangles

INDEX ON hypo TAG hypo
browse
The first condition in the where clause is there for speed's sake - we don't want Fox to even try combinations where the hypotenuse would be shorter; the second is to cut the result in half by eliminating 5, 3, 4 if we already have 5, 4, 3; and the third one is what takes the cake, that's Pythagora's rule. The rest is the icing on that cake.

Beware - Fox will sweat your machine over this for a while. I first tried with 32767, and had to kill it when some brow liquid started oozing out of my disks ;) (kidding)... the temp file it made was just about 1.2G. This is a three-way Cartesian product from which we're pulling a lot. So I went down to just first 800 hypotenuse sizes, and got 680 results, like this:
Hypo       	Cath1      	Cath2      	
          5	          4	          3	
         10	          8	          6	
         13	         12	          5	
         15	         12	          9	
         17	         15	          8	
         20	         16	         12	
         25	         24	          7	
         25	         20	         15	
         26	         24	         10	
         29	         21	         20	
         30	         24	         18	
         34	         30	         16	
         35	         28	         21	
         37	         35	         12	
         39	         36	         15	
         40	         32	         24	
         41	         40	          9	
         45	         36	         27	
         50	         48	         14	
         50	         40	         30	
         51	         45	         24	
         52	         48	         20	
         53	         45	         28	
         55	         44	         33	
         58	         42	         40	
...and 655 more.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform