From 6b17075cfaf5b3a01a41f85e629f3464b8e8e14a Mon Sep 17 00:00:00 2001 From: newt Date: Wed, 9 Oct 2024 18:02:34 +0100 Subject: [PATCH] (euler) - #5 --- euler/src/5 - Smallest Number.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 euler/src/5 - Smallest Number.ts diff --git a/euler/src/5 - Smallest Number.ts b/euler/src/5 - Smallest Number.ts new file mode 100644 index 0000000..df4f552 --- /dev/null +++ b/euler/src/5 - Smallest Number.ts @@ -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));