seunkoko seunkoko - 3 months ago
338 0

No description

Javascript

Pythagorean Triplets

function pythagoreanTriplets(){
    var add = 1000;
          k = 0;
        
    for (var i=1; i<add; i++){
      for(var j=i; j<add; j++){
        k = add - i - j;
        if ((square(i)+square(j)) === square(k)){
          return i + " * " + j + " * " + k + " = " + (i*j*k); 
        }
      }
    }
  }
  
  function square(val){
    return Math.pow(val, 2);
  }
  
  console.log(pythagoreanTriplets());