diff --git a/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json b/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json index 06d03ba59e..31e6bd1543 100644 --- a/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json +++ b/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json @@ -1579,23 +1579,23 @@ "type": "bonfire", "title": "Problem 44: Pentagon numbers", "tests": [ - "assert.strictEqual(euler44(), 5482660, 'message: euler44() should return 5482660.');" + "assert.strictEqual(pentagonNumbers(), 5482660, 'message: pentagonNumbers() 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 = |Pk − Pj| is minimised; what is the value of D?" + "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 = |Pk − Pj| is minimised; what is the value of D?" ] }, {