|
1604 | 1604 | "type": "bonfire",
|
1605 | 1605 | "title": "Problem 45: Triangular, pentagonal, and hexagonal",
|
1606 | 1606 | "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.');" |
1608 | 1608 | ],
|
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}"], |
1610 | 1610 | "translations": {},
|
1611 | 1611 | "challengeSeed": [
|
1612 |
| - "function euler45() {", |
| 1612 | + "function triPentaHexa(n) {", |
1613 | 1613 | " // Good luck!",
|
1614 | 1614 | " return true;",
|
1615 | 1615 | "}",
|
1616 | 1616 | "",
|
1617 |
| - "euler45();" |
| 1617 | + "triPentaHexa(40756);" |
1618 | 1618 | ],
|
1619 | 1619 | "description": [
|
1620 | 1620 | "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.", |
1637 | 1625 | "Find the next triangle number that is also pentagonal and hexagonal."
|
1638 | 1626 | ]
|
1639 | 1627 | },
|
|
0 commit comments