2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -0,0 +1,5 @@
|
|||
function sm35(n){
|
||||
var s=0, inc=[3,2,1,3,1,2,3]
|
||||
for (var j=6, i=0; i<n; j+=j==6?-j:1, i+=inc[j]) s+=i
|
||||
return s
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
function sm35(n){
|
||||
return tri(n,3) + tri(n,5) - tri(n,15)
|
||||
function tri(n, f) {
|
||||
n = Math.floor((n-1) / f)
|
||||
return f * n * (n+1) / 2
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for (var i=1, n=10; i<9; n*=10, i+=1) {
|
||||
document.write(10, '<sup>', i, '</sup> ', sm35(n), '<br>')
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
(() => {
|
||||
|
||||
// Area under straight line
|
||||
// between first multiple and last
|
||||
let sumMults = (n, factor) => {
|
||||
let n1 = Math.floor((n - 1) / factor);
|
||||
|
||||
return Math.floor(factor * n1 * (n1 + 1) / 2);
|
||||
},
|
||||
|
||||
sum35 = (n) => sumMults(n, 3) + sumMults(n, 5) - sumMults(n, 15);
|
||||
|
||||
|
||||
// TEST
|
||||
|
||||
// range(intFrom, intTo, optional intStep)
|
||||
// Int -> Int -> Maybe Int -> [Int]
|
||||
let range = (m, n, step) => {
|
||||
let d = (step || 1) * (n >= m ? 1 : -1);
|
||||
|
||||
return Array.from({
|
||||
length: Math.floor((n - m) / d) + 1
|
||||
}, (_, i) => m + (i * d));
|
||||
}
|
||||
|
||||
// Sums for 10^1 thru 10^8
|
||||
|
||||
return range(1, 8)
|
||||
.map(n => Math.pow(10, n))
|
||||
.reduce((a, x) => (
|
||||
a[x.toString()] = sum35(x),
|
||||
a
|
||||
), {});
|
||||
|
||||
})();
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{"10":23, "100":2318, "1000":233168, "10000":23331668,
|
||||
"100000":2333316668, "1000000":233333166668, "10000000":23333331666668,
|
||||
"100000000":2333333316666668}
|
||||
Loading…
Add table
Add a link
Reference in a new issue