Skip to content

Commit b3159b9

Browse files
authored
add Euler problem 6 (#470)
1 parent be95cc4 commit b3159b9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Project-Euler/Problem6.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://projecteuler.net/problem=6
2+
3+
const num = 100 // number we are checking; change to 10 to check 10 from example
4+
5+
const squareDifference = (num) => {
6+
let sumOfSquares = 0
7+
let sums = 0
8+
for (let i = 1; i <= num; i++) {
9+
sumOfSquares += i ** 2 // add squares to the sum of squares
10+
sums += i // add number to sum to square later
11+
}
12+
return (sums ** 2) - sumOfSquares // difference of square of the total sum and sum of squares
13+
}
14+
15+
console.log(squareDifference(num))

0 commit comments

Comments
 (0)