Compute Pythagorean Tripple

[Total: 0    Average: 0/5]

This shows how to compute a pythagorean triple.

Body Code:

n in {1,2,3,4,...}
t = floor( (3+sqrt(8*n-7))/2 )
s = n -(t^2-3*t+2)/2
x = 2*s*t
y = t^2 -s^2
z = t^2 +s^2
{x,y,z} is a Pythagorean triple
var MAX=250;
for (var n=1;n<=MAX;n++)
  var t=Math.floor((3+Math.sqrt(8*n-7))/2);
  var s=n-(Math.pow(t,2)-3*t+2)/2;
  var x=2*s*t;
  var y=Math.pow(t,2)-Math.pow(s,2);
  var z=Math.pow(t,2)+Math.pow(s,2);
  document.write("{"+x+","+y+","+z+"} is a Pythagorean triple.<BR>");

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *