fix(challenges): Edit Description and Add Solution for Project Euler 45 (#17126)
Updated the problem description with an inline CSS grid, <sup>, and <var> tags. Also added a solution that user @elliotjz contributed to the fCC Arcade Mode. BREAKING CHANGE: Nonepull/18182/head
parent
cca9b8b3a8
commit
6586ecd5b6
|
@ -1604,36 +1604,24 @@
|
|||
"type": "bonfire",
|
||||
"title": "Problem 45: Triangular, pentagonal, and hexagonal",
|
||||
"tests": [
|
||||
"assert.strictEqual(euler45(), 1533776805, 'message: <code>euler45()</code> should return 1533776805.');"
|
||||
"assert.strictEqual(triPentaHexa(40756), 1533776805, 'message: <code>triPentaHexa(40756)</code> should return 1533776805.');"
|
||||
],
|
||||
"solutions": [],
|
||||
"solutions": ["function triPentaHexa(n) {\n function triangular(num) {\n return (num * (num + 1)) / 2;\n}\n\nfunction isPentagonal(num) {\n // Formula found by completing the square and\n // solving for n.\n const n = (Math.sqrt((24 * num) + 1) + 1) / 6;\n return n % 1 === 0;\n}\n\n function isHexagonal(num) {\n // Formula found by completing the square and\n // solving for n.\n const n = Math.sqrt(0.5 * (num + (1 / 8))) + 0.25;\n return n % 1 === 0;\n}\n\nlet iTri = n;\nlet tri;\nlet found = false;\nwhile (!found) {\n iTri++;\n tri = triangular(iTri);\n if (isPentagonal(tri) && isHexagonal(tri)) {\n found = true;\n }\n }\n return tri;\n}"],
|
||||
"translations": {},
|
||||
"challengeSeed": [
|
||||
"function euler45() {",
|
||||
"function triPentaHexa(n) {",
|
||||
" // Good luck!",
|
||||
" return true;",
|
||||
"}",
|
||||
"",
|
||||
"euler45();"
|
||||
"triPentaHexa(40756);"
|
||||
],
|
||||
"description": [
|
||||
"Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:",
|
||||
"Triangle",
|
||||
"",
|
||||
"Tn=n(n+1)/2",
|
||||
"",
|
||||
"1, 3, 6, 10, 15, ...",
|
||||
"Pentagonal",
|
||||
"",
|
||||
"Pn=n(3n−1)/2",
|
||||
"",
|
||||
"1, 5, 12, 22, 35, ...",
|
||||
"Hexagonal",
|
||||
"",
|
||||
"Hn=n(2n−1)",
|
||||
"",
|
||||
"1, 6, 15, 28, 45, ...",
|
||||
"It can be verified that T285 = P165 = H143 = 40755.",
|
||||
"<div style='display: inline-grid; text-align: center; grid-template-columns: repeat(3, minmax(117px, 12%)); grid-template-rows: auto;'><div>Triangle</div><div>T<sub>n</sub>=<var>n</var>(<var>n</var>+1)/2</div><div>1, 3, 6, 10, 15, ...</div></div>",
|
||||
"<div style='display: inline-grid; text-align: center; grid-template-columns: repeat(3, minmax(117px, 12%)); grid-template-rows: auto;'><div>Pentagonal</div><div>P<sub>n</sub>=<var>n</var>(3<var>n</var>−1)/2</div><div>1, 5, 12, 22, 35, ...</div></div>",
|
||||
"<div style='display: inline-grid; text-align: center; grid-template-columns: repeat(3, minmax(117px, 12%)); grid-template-rows: auto;'><div>Hexagonal</div><div>H<sub>n</sub>=<var>n</var>(2<var>n</var>−1)</div><div>1, 6, 15, 28, 45, ...</div></div>",
|
||||
"It can be verified that T<sub>285</sub> = P<sub>165</sub> = H<sub>143</sub> = 40755.",
|
||||
"Find the next triangle number that is also pentagonal and hexagonal."
|
||||
]
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue