September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,35 +1,36 @@
(() => {
// Area under straight line
// between first multiple and last
let sumMults = (n, factor) => {
let n1 = Math.floor((n - 1) / factor);
// between first multiple and last.
return Math.floor(factor * n1 * (n1 + 1) / 2);
},
// sumMults :: Int -> Int -> Int
const sumMults = (n, factor) => {
const n1 = quot(n - 1, factor);
return quot(factor * n1 * (n1 + 1), 2);
};
sum35 = (n) => sumMults(n, 3) + sumMults(n, 5) - sumMults(n, 15);
// sum35 :: Int -> Int
const sum35 = n => sumMults(n, 3) + sumMults(n, 5) - sumMults(n, 15);
// TEST
// GENERIC ----------------------------------------------------------------
// range(intFrom, intTo, optional intStep)
// Int -> Int -> Maybe Int -> [Int]
let range = (m, n, step) => {
let d = (step || 1) * (n >= m ? 1 : -1);
// enumFromTo :: Int -> Int -> [Int]
const enumFromTo = (m, n) =>
Array.from({
length: Math.floor(n - m) + 1
}, (_, i) => m + i);
return Array.from({
length: Math.floor((n - m) / d) + 1
}, (_, i) => m + (i * d));
}
// Integral a => a -> a -> a
const quot = (n, m) => Math.floor(n / m);
// TEST -------------------------------------------------------------------
// Sums for 10^1 thru 10^8
return range(1, 8)
return enumFromTo(1, 8)
.map(n => Math.pow(10, n))
.reduce((a, x) => (
a[x.toString()] = sum35(x),
a
), {});
})();