Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, February 4, 2013

Math Problem: Square Root Sums


Question:

How many pairs of integers (x,y) will satisfy the following equation:
sqrt(x) + sqrt(y) = sqrt(432)

Answer: 13

Solution: Solved using the script below


console.log("----------------------------------");
function comp(a,b){
var temp = Math.sqrt(a)+Math.sqrt(b);
if(temp == Math.sqrt(432)){
return true;
} else {
return false;
}
}
var max=10000;
var count=0;
for(var i=0; i<max; i++){
for(var j=0; j<max; j++){
var temp=comp(i,j);
if(temp){
console.log(i+" "+j);
count++;
}
}
}
console.log("count is " + count);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts