Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Commit 6586ecd

Browse files
scissorsneedfoodtoomstellaluna
authored andcommitted
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: None
1 parent cca9b8b commit 6586ecd

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,36 +1604,24 @@
16041604
"type": "bonfire",
16051605
"title": "Problem 45: Triangular, pentagonal, and hexagonal",
16061606
"tests": [
1607-
"assert.strictEqual(euler45(), 1533776805, 'message: <code>euler45()</code> should return 1533776805.');"
1607+
"assert.strictEqual(triPentaHexa(40756), 1533776805, 'message: <code>triPentaHexa(40756)</code> should return 1533776805.');"
16081608
],
1609-
"solutions": [],
1609+
"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}"],
16101610
"translations": {},
16111611
"challengeSeed": [
1612-
"function euler45() {",
1612+
"function triPentaHexa(n) {",
16131613
" // Good luck!",
16141614
" return true;",
16151615
"}",
16161616
"",
1617-
"euler45();"
1617+
"triPentaHexa(40756);"
16181618
],
16191619
"description": [
16201620
"Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:",
1621-
"Triangle",
1622-
"",
1623-
"Tn=n(n+1)/2",
1624-
"",
1625-
"1, 3, 6, 10, 15, ...",
1626-
"Pentagonal",
1627-
"",
1628-
"Pn=n(3n−1)/2",
1629-
"",
1630-
"1, 5, 12, 22, 35, ...",
1631-
"Hexagonal",
1632-
"",
1633-
"Hn=n(2n−1)",
1634-
"",
1635-
"1, 6, 15, 28, 45, ...",
1636-
"It can be verified that T285 = P165 = H143 = 40755.",
1621+
"<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>",
1622+
"<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>",
1623+
"<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>",
1624+
"It can be verified that T<sub>285</sub> = P<sub>165</sub> = H<sub>143</sub> = 40755.",
16371625
"Find the next triangle number that is also pentagonal and hexagonal."
16381626
]
16391627
},

0 commit comments

Comments
 (0)