fix(seed): Add tests, solution, and edit description for Project Euler 16 (#16641)
Edited the description so the exponents are displayed properly, and added more tests and a solution. Amend: Edited the seed so that the challenge function in the seed is called only once. BREAKING CHANGE: None
This commit is contained in:
committed by
Stuart Taylor
parent
4a3d1c9dce
commit
5d14e4bdd5
@ -721,21 +721,23 @@
|
|||||||
"type": "bonfire",
|
"type": "bonfire",
|
||||||
"title": "Problem 16: Power digit sum",
|
"title": "Problem 16: Power digit sum",
|
||||||
"tests": [
|
"tests": [
|
||||||
"assert.strictEqual(euler16(), 1366, 'message: <code>euler16()</code> should return 1366.');"
|
"assert.strictEqual(powerDigitSum(15), 26, 'message: <code>powerDigitSum(15)</code> should return 26.');",
|
||||||
|
"assert.strictEqual(powerDigitSum(128), 166, 'message: <code>powerDigitSum(128)</code> should return 166.');",
|
||||||
|
"assert.strictEqual(powerDigitSum(1000), 1366, 'message: <code>powerDigitSum(1000)</code> should return 1366.');"
|
||||||
],
|
],
|
||||||
"solutions": [],
|
"solutions": ["function powerDigitSum(exponent) {\n const bigNum = [1];\n let sum = 0;\n\n for (let i = 1; i <= exponent; i++) {\n let count = bigNum.length + 1;\n let overflow = 0;\n for (let j = 0; j < count; j++) {\n let digit = bigNum[j] || 0;\n digit = 2 * digit + overflow;\n\n if (digit > 9) {\n digit -= 10;\n overflow = 1;\n } else {\n overflow = 0;\n }\n\n bigNum[j] = digit;\n }\n }\n\n bigNum.forEach(function(num) {\n return sum += num;\n });\n\n return sum;\n}"],
|
||||||
"translations": {},
|
"translations": {},
|
||||||
"challengeSeed": [
|
"challengeSeed": [
|
||||||
"function euler16() {",
|
"function powerDigitSum(exponent) {",
|
||||||
" // Good luck!",
|
" // Good luck!",
|
||||||
" return true;",
|
" return true;",
|
||||||
"}",
|
"}",
|
||||||
"",
|
"",
|
||||||
"euler16();"
|
"powerDigitSum(15);"
|
||||||
],
|
],
|
||||||
"description": [
|
"description": [
|
||||||
"215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.",
|
"2¹⁵ = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.",
|
||||||
"What is the sum of the digits of the number 21000?"
|
"What is the sum of the digits of the number 2¹⁰⁰⁰?"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user