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

Sunday, January 27, 2013

Math Problems: Sum of two-digit numbers


Question:

If we sum all two digit numbers whose digits are made up of combinations of the numbers 1, 2, 3, 4, what is the result?

Answer: 440

Solution: Solved using the script below


console.log("*********************************");
function cati(string, index){
if(string.charAt(index)==='1' || string.charAt(index)==='2' || string.charAt(index)==='3' || string.charAt(index)==='4'){
return true;
}
else {
return false;
}
}

var sum=0;
for(var i=0; i<100; i++){
if(i>=10){
var temp = i.toString();
if(cati(temp,0) && cati(temp,1)){
console.log(temp);
sum+=i;
}
}
}
console.log("Sum is "+sum);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts