Skip to content

Commit eb0005f

Browse files
authored
Merge pull request TheAlgorithms#488 from Waddah-JD/project-euler-problem-005
Project Euler problem 005 solution
2 parents 8ccc816 + de4504f commit eb0005f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Project-Euler/Problem5.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Smallest multiple
3+
4+
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
5+
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
6+
*/
7+
8+
const findSmallestMultiple = () => {
9+
const divisors = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
10+
let num = 21
11+
let result
12+
13+
while (!result) {
14+
const isDivisibleByAll = divisors.every((divisor) => num % divisor === 0)
15+
if (isDivisibleByAll) result = num
16+
else num++
17+
}
18+
19+
return result
20+
}
21+
22+
console.log(findSmallestMultiple())

0 commit comments

Comments
 (0)