Skip to content

Commit

Permalink
fix(challenges): Edit Description and Add Solution for Project Euler …
Browse files Browse the repository at this point in the history
…44 (#17127)

Updated the problem description with <sup> and <var> tags, and centered
some text. Also, added a solution that user @elliotjz contributed to the
fCC Arcade Mode.

BREAKING CHANGE: None
  • Loading branch information
scissorsneedfoodtoo authored and raisedadead committed May 6, 2018
1 parent 3f09b23 commit 1325cc0
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1579,23 +1579,23 @@
"type": "bonfire",
"title": "Problem 44: Pentagon numbers",
"tests": [
"assert.strictEqual(euler44(), 5482660, 'message: <code>euler44()</code> should return 5482660.');"
"assert.strictEqual(pentagonNumbers(), 5482660, 'message: <code>pentagonNumbers()</code> should return 5482660.');"
],
"solutions": [],
"solutions": ["function pentagonNumbers() {\n function isPentagonal(num) {\n // Formula found by solving pentagonal number\n // equation for n.\n const n = (Math.sqrt((24 * num) + 1) + 1) / 6;\n return n % 1 === 0;\n }\n\n function pentagonal(num) {\n return (num * ((3 * num) - 1)) / 2;\n }\n let result;\n let i = 1;\n while (!result) {\n i++;\n const num1 = (i * ((3 * i) - 1)) / 2; // Pentagonal num formula\n const minDiff = num1 - (((i - 1) * ((3 * (i - 1)) - 1)) / 2);\n let j = i - 1;\n while (j > 0 && !result) {\n const num2 = (j * ((3 * j) - 1)) / 2;\n if (isPentagonal(num1 - num2) && isPentagonal(num1 + num2)) {\n result = num1 - num2;\n }\n j--;\n }\n }\n return result;\n }"],
"translations": {},
"challengeSeed": [
"function euler44() {",
"function pentagonNumbers() {",
" // Good luck!",
" return true;",
"}",
"",
"euler44();"
"pentagonNumbers();"
],
"description": [
"Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten pentagonal numbers are:",
"1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...",
"It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 − 22 = 48, is not pentagonal.",
"Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference are pentagonal and D = |PkPj| is minimised; what is the value of D?"
"Pentagonal numbers are generated by the formula, P<sub>n</sub>=<var>n</var>(3<var>n</var>−1)/2. The first ten pentagonal numbers are:",
"<span style='display: block; text-align: center;'>1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...</span>",
"It can be seen that P<sub>4</sub> + P<sub>7</sub> = 22 + 70 = 92 = P<sub>8</sub>. However, their difference, 70 − 22 = 48, is not pentagonal.",
"Find the pair of pentagonal numbers, P<sub>j</sub> and P<sub>k</sub>, for which their sum and difference are pentagonal and D = |P<sub>k</sub>P<sub>j</sub>| is minimised; what is the value of D?"
]
},
{
Expand Down

0 comments on commit 1325cc0

Please sign in to comment.