Created
July 27, 2017 23:56
-
-
Save marcmartino/bf002ecb71f1dc98f30ff14982de0b6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//jshint esnext:true | |
/* | |
Multiples of 3 and 5 | |
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. | |
*/ | |
// getMultiples :: Integer -> Integer -> [Integer] | |
const getMultiples = R.curry((max, mult) => R.compose(R.map(R.multiply(mult)), | |
R.range(1))(parseInt(max / mult) + 1)) | |
// sumOfMultiples :: [Integer] -> Integer | |
const sumOfMultiples = R.compose(R.reduce(R.add, 0), | |
R.uniq, | |
R.apply(R.concat), | |
R.map(getMultiples(1000))); | |
console.log(sumOfMultiples([5,3])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment