From a88cdee9c356a2012d97e458f9b35e36c5b369b9 Mon Sep 17 00:00:00 2001 From: Kristofer Koishigawa Date: Sat, 28 Apr 2018 18:01:23 +0900 Subject: [PATCH] fix(challenges): Edit Description and Add Solution for Project Euler 38 (#17086) Updated the problem description with `` tags and improved the formatting. Also added a solution that user @elliotjz contributed to the fCC Arcade Mode. BREAKING CHANGE: None --- .../project-euler-problems.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 c26d3c3f3c9..8e1fd80aeec 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 @@ -1410,26 +1410,26 @@ "type": "bonfire", "title": "Problem 38: Pandigital multiples", "tests": [ - "assert.strictEqual(euler38(), 932718654, 'message: euler38() should return 932718654.');" + "assert.strictEqual(pandigitalMultiples(), 932718654, 'message: pandigitalMultiples() should return 932718654.');" ], - "solutions": [], + "solutions": ["function pandigitalMultiples() {\n\n function get9DigitConcatenatedProduct(num) {\n // returns false if concatenated product is not 9 digits\n let concatenatedProduct = num.toString();\n for (let i = 2; concatenatedProduct.length < 9; i++) {\n concatenatedProduct += num * i;\n }\n return concatenatedProduct.length === 9 ? concatenatedProduct : false;\n }\n\n function is1to9Pandigital(num) {\n const numStr = num.toString();\n\n // check if length is not 9\n if (numStr.length !== 9) {\n return false;\n }\n\n // check if pandigital\n for (let i = 9; i > 0; i--) {\n if (numStr.indexOf(i.toString()) === -1) {\n return false;\n }\n }\n return true;\n }\n\n let largestNum = 0;\n for (let i = 9999; i >= 9000; i--) {\n const concatenatedProduct = get9DigitConcatenatedProduct(i);\n if (is1to9Pandigital(concatenatedProduct) && concatenatedProduct > largestNum) {\n largestNum = parseInt(concatenatedProduct);\n break;\n }\n }\n return largestNum;\n}"], "translations": {}, "challengeSeed": [ - "function euler38() {", + "function pandigitalMultiples() {", " // Good luck!", " return true;", "}", "", - "euler38();" + "pandigitalMultiples();" ], "description": [ "Take the number 192 and multiply it by each of 1, 2, and 3:", "192 × 1 = 192", "192 × 2 = 384", "192 × 3 = 576", - "By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)", - "The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).", - "What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?" + "By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1, 2, 3).", + "The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1, 2, 3, 4, 5).", + "What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1, 2, ... , n) where n > 1?" ] }, {