* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.2 KiB
1.2 KiB
id, title, challengeType, videoUrl, dashedName
id | title | challengeType | videoUrl | dashedName |
---|---|---|---|---|
5900f3801000cf542c50fe93 | 问题20:因子数字和 | 5 | problem-20-factorial-digit-sum |
--description--
n
!意味着n
×( n
- 1)×...×3×2×1例如,10! = 10×9×...×3×2×1 = 3628800,
和数字10中的数字之和!是3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.找到数字之和n
!
--hints--
sumFactorialDigits(10)
应该返回27。
assert.strictEqual(sumFactorialDigits(10), 27);
sumFactorialDigits(25)
应该返回72。
assert.strictEqual(sumFactorialDigits(25), 72);
sumFactorialDigits(50)
应该返回216。
assert.strictEqual(sumFactorialDigits(50), 216);
sumFactorialDigits(75)
应该返回432。
assert.strictEqual(sumFactorialDigits(75), 432);
sumFactorialDigits(100)
应该返回648。
assert.strictEqual(sumFactorialDigits(100), 648);
--seed--
--seed-contents--
function sumFactorialDigits(n) {
return n;
}
sumFactorialDigits(100);
--solutions--
let factorial = (n) => n <= 1 ? BigInt(n) : BigInt(n) * BigInt(factorial(--n));
let sumDigits = n => n.toString().split('').map(x => parseInt(x)).reduce((a,b) => a + b);
function sumFactorialDigits(n) {
return sumDigits(factorial(n));
}