* 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>
64 lines
1.4 KiB
Markdown
64 lines
1.4 KiB
Markdown
---
|
||
id: 5900f3941000cf542c50fea7
|
||
title: 问题40:Champernowne的常数
|
||
challengeType: 5
|
||
videoUrl: ''
|
||
dashedName: problem-40-champernownes-constant
|
||
---
|
||
|
||
# --description--
|
||
|
||
通过连接正整数创建无理小数: 0.12345678910 **1** 112131415161718192021 ...可以看出小数部分的<sup>第</sup> 12位是1.如果*d <sub>n</sub>*代表小数部分的<sup>第</sup> *n*位,找到值以下表达式。 d <sub>1</sub> ×d <sub>10</sub> ×d <sub>100</sub> ×d <sub>1000</sub> ×d <sub>10000</sub> ×d <sub>100000</sub> ×d <sub>1000000</sub>
|
||
|
||
# --hints--
|
||
|
||
`champernownesConstant(100)`应该返回5。
|
||
|
||
```js
|
||
assert.strictEqual(champernownesConstant(100), 5);
|
||
```
|
||
|
||
`champernownesConstant(1000)`应该返回15。
|
||
|
||
```js
|
||
assert.strictEqual(champernownesConstant(1000), 15);
|
||
```
|
||
|
||
`champernownesConstant(1000000)`应该返回210。
|
||
|
||
```js
|
||
assert.strictEqual(champernownesConstant(1000000), 210);
|
||
```
|
||
|
||
# --seed--
|
||
|
||
## --seed-contents--
|
||
|
||
```js
|
||
function champernownesConstant(n) {
|
||
|
||
return true;
|
||
}
|
||
|
||
champernownesConstant(100);
|
||
```
|
||
|
||
# --solutions--
|
||
|
||
```js
|
||
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;
|
||
}
|
||
```
|