I am a Computer Science and I am having a problem on writing this perl program for one of my classes. i haven't taken perl in about two years and do not remember how to set the syntax up or execute the program. Am I suppose to use C++? The class that I am taking is Web Applications. The program states the following:
A right triangle can have sides that ate all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse ( famous a^2+b^2=c^2 formula). Find all Pythagorean triples that are not larger than 500 for side, side2, and hypotenuse. Use a triple nested for loop that tries all possibilities.

I do not need the full program. I just need to know the syntax to set the triples up and how I would execute the program.

12 Years
Discussion Span
Last Post by Shon05


for $x (1..500) {
    for $y (1..500) {
        for $z (1..500) {
            # the rest is up to you :)

Now you just have to check if $x, $y and $z are a pythagorean triple. But beware of double counts, because 3^2 + 4^2 = 5^2 and so is 4^2 + 3^2 ;)

Regards, mawe


Thanks I will try working through the program with that loop and I will get back with you.
Thanks again!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.