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

Sunday, January 27, 2013

Math Problems: Function Perfect Square


Question: What is the sum of all positive integers that will allow the evaluated function  f(x) = x^2 + 19x + 130 to be a perfect square?

Answer: 33

Solved using the script below:


console.log("*************************************")
function isInt(value) {
    return !isNaN(parseInt(value,10)) && (parseFloat(value,10) == parseInt(value,10));
}

function someF(x){
return (x*x)+(19*x)+130;
}
var max=100000;
for(var i=0; i<max; i++){
temp = someF(i);
temp2 = Math.sqrt(temp);
if(isInt(temp2)){
console.log("i:"+i+" someFunc:"+temp+" sqrt:"+temp2);
}
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts