Pythagorean Triplet Finder in Ruby

A Pythagorean Triplet is a set of three numbers, a, b, c that satisfy this condition.

a^2+b^2=c^2

For example, 3, 4, and 5 make up a Pythagorean Triplet.

Now the question is, can we create program that find all pairs of numbers that create Pythagorean Triplets with a given number?

Check out my solution here.

While the both method works fine, the second method utilizes Triangular inequality. This omits extra looping that's unnecessary and saves tons of run time.

When n was 10000, method 1 took 8.720612 seconds and method 2 took 5.516031 seconds. Method 2 is 58.1% faster than method 1.