diff --git a/seed/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json b/seed/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json index 31e6bd15430..656c90bd575 100644 --- a/seed/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json +++ b/seed/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json @@ -1604,36 +1604,24 @@ "type": "bonfire", "title": "Problem 45: Triangular, pentagonal, and hexagonal", "tests": [ - "assert.strictEqual(euler45(), 1533776805, 'message: euler45() should return 1533776805.');" + "assert.strictEqual(triPentaHexa(40756), 1533776805, 'message: triPentaHexa(40756) 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.", + "
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.", "Find the next triangle number that is also pentagonal and hexagonal." ] },