fix(challenges): Edit Description, Add Tests and Solution for Project Euler 40 (#17087)

Updated the problem description to more closely match the one on the Project Euler page. Also added more tests along with a solution that user @elliotjz contributed to the fCC Arcade Mode.

BREAKING CHANGE: None
pull/18182/head
Kristofer Koishigawa 2018-04-28 18:01:51 +09:00 committed by mrugesh mohapatra
parent a88cdee9c3
commit 1b99e6d297
1 changed files with 10 additions and 8 deletions

View File

@ -1465,24 +1465,26 @@
"type": "bonfire",
"title": "Problem 40: Champernowne's constant",
"tests": [
"assert.strictEqual(euler40(), 210, 'message: <code>euler40()</code> should return 210.');"
"assert.strictEqual(champernownesConstant(100), 5, 'message: <code>champernownesConstant(100)</code> should return 5.');",
"assert.strictEqual(champernownesConstant(1000), 15, 'message: <code>champernownesConstant(1000)</code> should return 15.');",
"assert.strictEqual(champernownesConstant(1000000), 210, 'message: <code>champernownesConstant(1000000)</code> should return 210.');"
],
"solutions": [],
"solutions": ["function champernownesConstant(n) {\n let fractionalPart = '';\n for (let i = 0; fractionalPart.length <= n; i++) {\n fractionalPart += i.toString();\n }\n\n let product = 1;\n for (let i = 0; i < n.toString().length; i++) {\n const index = 10 ** i;\n product *= parseInt(fractionalPart[index], 10);\n }\n\n return product;\n}"],
"translations": {},
"challengeSeed": [
"function euler40() {",
"function champernownesConstant(n) {",
" // Good luck!",
" return true;",
"}",
"",
"euler40();"
"champernownesConstant(100);"
],
"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"
"<span style='display: block; text-align: center;'>0.12345678910<b style='color: red;'>1</b>112131415161718192021...</span>",
"It can be seen that the 12<sup>th</sup> digit of the fractional part is 1.",
"If <i>d<sub>n</sub></i> represents the <i>n</i><sup>th</sup> digit of the fractional part, find the value of the following expression.",
"<span style='display: block; text-align: center;'>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></span>"
]
},
{