I did euler problem nine in javascript. That's the finding a^2 + b^2 = c^2 where a+b+c = 1000. It was just one method with a nested loop. I wrote a test at the end but I'm not sure it's worth refactoring into more testable functions... might be interesting to do an exploration of functional programming with something simple like this.
function euler_9(){
var answer;
for(let a=2; a<1000; a++){
for(let b=2; b<1000; b++){
let c = Math.sqrt(a*a + b*b)
if(a + b + c == 1000){
answer = a*b*c
}
}
}
return answer
}
| last modified | size | ||
| euler_9.js | Sat Dec 06 2025 03:50 pm | 423B | |
| euler_9.test.js | Sat Dec 06 2025 03:50 pm | 160B |