(euler) - #5
This commit is contained in:
parent
693642ec36
commit
6b17075cfa
1 changed files with 19 additions and 0 deletions
19
euler/src/5 - Smallest Number.ts
Normal file
19
euler/src/5 - Smallest Number.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* Is x disible to n?
|
||||
*/
|
||||
const isDivisibleTo = (x: number, n: number) => {
|
||||
for (; n > 0; n -= 1) {
|
||||
if (x % n !== 0) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const divisibleTo = (n: number) => {
|
||||
if (n === 1) return 1;
|
||||
|
||||
for (var step = divisibleTo(n - 1), i = step; !isDivisibleTo(i, n); i += step);
|
||||
return i;
|
||||
};
|
||||
|
||||
console.log(divisibleTo(20));
|
Loading…
Reference in a new issue