wood burning stoves 2.0*
The moose likes Programming Diversions and the fly likes An easy math/programming puzzle. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "An easy math/programming puzzle." Watch "An easy math/programming puzzle." New topic
Author

An easy math/programming puzzle.

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
You have your choice of writing a program to solve this one or just doing it in your head.

How many different right triangles with all integer sides have one side of length 60?

Ryan
Arjunkumar Shastry
Ranch Hand

Joined: Feb 28, 2005
Posts: 986
Side or hypotenuse of length 60? Anyway,following program prints some of the triplets.

The above program prints only prime triplets.For example,(3,4,5) but not (6,8,10).If any prime triplet contains the factor of 60,then prime triplet can be converted to corresponding triplet which will have a side of 60.
From i=2 to i=1000,I was able to find only four prime triplets:
(11,60,61)
(60,91,109)
(60,221,229)
(60,899,901)
Some of the interesting facts about prime triplets:
(x,y) = (y,z) = (z,x) = 1 where (x,y)--> gcd of x & y.
Only one of x,y,z is even.Other two are odd.
[ May 08, 2005: Message edited by: Arjunkumar Shastry ]
[ May 08, 2005: Message edited by: Arjunkumar Shastry ]

Namma Suvarna Karnataka
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Originally posted by Ryan McGuire:
You have your choice of writing a program to solve this one or just doing it in your head.

How many different right triangles with all integer sides have one side of length 60?

Ryan


Well, I don't know if it is possible to calculate all of them in you head, but this is what I got from writing a program to calculate it.



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Ryan McGuire:
You have your choice of writing a program to solve this one or just doing it in your head.

How many different right triangles with all integer sides have one side of length 60?

Ryan


If the 60-side is not the hypotenuse, I think there are infinite possibilites. The other two sides could approach infinity and still make a right triangle.


A good workman is known by his tools.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Originally posted by Marc Peabody:

If the 60-side is not the hypotenuse, I think there are infinite possibilites. The other two sides could approach infinity and still make a right triangle.


There may be infinite possibilities for right triangles, but they can't satisfy the criteria.

As one side, and the hypotenuse, grows toward infinitely... the smallest the hypotenuse can be is the growing side plus one. And as this number gets bigger, this small plus one will cause the third side to be much greater than 60 to try to satisfy the condition.

Henry
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11168
    
  16

I think there are infinite possibilites.

i don't think that's true. eventually, you will reach the point where if one leg is x, and the hypotenuse is x+1, the difference between the two will be more than 60^2. and, any hypotenuse more than 1 greater will result in a bigger difference...

i haven't done any math, but i think i'm right...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
Consider:

60^2 + x^2 = (x+n)^2
3600 + x^2 = x^2 + 2xn + n^2
(3600 - n^2)/2n = x

Since n^2 >= 2n when n > 1, and the smallest difference between x and n is 1, then the largest possible x is when n is 1. That would mean that for all triangles fulfilling the requirements, x < 1800
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Originally posted by Timmy Marks:
Consider:

60^2 + x^2 = (x+n)^2
3600 + x^2 = x^2 + 2xn + n^2
(3600 - n^2)/2n = x

Since n^2 >= 2n when n > 1, and the smallest difference between x and n is 1, then the largest possible x is when n is 1. That would mean that for all triangles fulfilling the requirements, x < 1800


Thanks... I had some complex formula to determine whether to stop or not. This formula is much easier to use...

Henry
[ May 09, 2005: Message edited by: Henry Wong ]
Arjunkumar Shastry
Ranch Hand

Joined: Feb 28, 2005
Posts: 986
The last triplet which contains 60 seems to be now (60,899,901).
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by Henry Wong:

Well, I don't know if it is possible to calculate all of them in you head, but this is what I got from writing a program to calculate it.

I did them all in my head but had to use paper to keep track of them as I found them.

The way I looked at it was that 60^2 had to be enough to pad one square out to the size of another. To do this, 3600 had to be cut up into three pieces: two that are as long as the smaller square and n wide, plus a small n*n block. For instance, when n=2, the small 2*2 block takes 4 out of the 3600 leaving 3596. That means that 3594 had to make two 2*something blocks. That "something" is 3596/4 or 899. That make 60/899/901 a solution.

As a negative example... when n=3, n^2=9, leaving 3591. You can't split 3599 into two equal 3*(some integer) pieces. This can be said about all odd values for n.

Or, more "algorithmically",...


You might recognize that formula for x from what Timmy Marks posted. Why did I stop at n<=25? Because I don't have 26^2 memorized.

The first five (plus 60/80/100) are just multiples of 3/4/5, 5/12/13, or 8/15/17 triangles.

Ryan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: An easy math/programming puzzle.
 
Similar Threads
Null Global JNDI Error
Need Suggestion
DeploymentException while deploying ear file in JBoss
HOW TO: Deploy an Application Client in WAS
Server crash