Created
March 16, 2018 18:29
-
-
Save robherley/947267075ff602ede7e91b7eb744b819 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
const MOD = 1000000007; | |
const samSubstr = balls => | |
[...balls].reduceRight( | |
(prev, digit, i) => { | |
return [ | |
(prev[0] * 10 + 1) % MOD, | |
(prev[1] + ~~digit * prev[0] * (i + 1)) % MOD | |
]; | |
}, | |
[1, 0] | |
)[1]; | |
console.log(samSubstr('16')); // 23 | |
console.log(samSubstr('23')); // 164 | |
console.log(samSubstr('1337')); // 1904 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment