Latest
parent
273de564c2
commit
75e23e985e
|
@ -81,6 +81,8 @@
|
||||||
|
|
||||||
go
|
go
|
||||||
gofumpt
|
gofumpt
|
||||||
|
|
||||||
|
nodejs
|
||||||
]);
|
]);
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|
|
@ -10,6 +10,8 @@ Find the sum of all the multiples of 3 or 5 below 1000.
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Data.List (union)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = print ans
|
main = print ans
|
||||||
|
|
||||||
|
@ -32,3 +34,8 @@ allXsUnderN x n = filter (isMultipleOf x) [1..n-1]
|
||||||
|
|
||||||
allNumbersUnder :: Integral a => a -> [a]
|
allNumbersUnder :: Integral a => a -> [a]
|
||||||
allNumbersUnder l = allXsUnderN 3 l <> allXsUnderN 5 l
|
allNumbersUnder l = allXsUnderN 3 l <> allXsUnderN 5 l
|
||||||
|
|
||||||
|
|
||||||
|
_3s = [3,6..999]
|
||||||
|
_5s = [5,10..999]
|
||||||
|
solution = sum $ union _3s _5s
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
https://projecteuler.net/problem=1
|
||||||
|
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
|
||||||
|
The sum of these multiples is 23.
|
||||||
|
|
||||||
|
Find the sum of all the multiples of 3 or 5 below 1000.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const isMultipleOf = (m) => (n) => n % m === 0;
|
||||||
|
const is3_ = isMultipleOf(3);
|
||||||
|
const is5_ = isMultipleOf(5);
|
||||||
|
|
||||||
|
const is3 = (n) => n % 3 === 0;
|
||||||
|
const is5 = (n) => n % 5 === 0;
|
||||||
|
|
||||||
|
const limit = 1000;
|
||||||
|
let result = 0;
|
||||||
|
for (let i = 0; i < limit; i++) {
|
||||||
|
if (is3(i) || is5(i)) {
|
||||||
|
result += i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Answer is ${result}`);
|
Loading…
Reference in New Issue