* 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.6 KiB
1.6 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
5900f3941000cf542c50fea7 | Problem 40: Champernowne's constant | 5 | 302066 | problem-40-champernownes-constant |
--description--
An irrational decimal fraction is created by concatenating the positive integers:
0.123456789101112131415161718192021...
It can be seen that the 12th digit of the fractional part is 1.
If dn represents the nth digit of the fractional part, find the value of the following expression.
d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
--hints--
champernownesConstant(100)
should return a number.
assert(typeof champernownesConstant(100) === 'number');
champernownesConstant(100)
should return 5.
assert.strictEqual(champernownesConstant(100), 5);
champernownesConstant(1000)
should return 15.
assert.strictEqual(champernownesConstant(1000), 15);
champernownesConstant(1000000)
should return 210.
assert.strictEqual(champernownesConstant(1000000), 210);
--seed--
--seed-contents--
function champernownesConstant(n) {
return true;
}
champernownesConstant(100);
--solutions--
function champernownesConstant(n) {
let fractionalPart = '';
for (let i = 0; fractionalPart.length <= n; i++) {
fractionalPart += i.toString();
}
let product = 1;
for (let i = 0; i < n.toString().length; i++) {
const index = 10 ** i;
product *= parseInt(fractionalPart[index], 10);
}
return product;
}