From 1b99e6d2977a8429dca31fbfaeb461dd06dffbb1 Mon Sep 17 00:00:00 2001 From: Kristofer Koishigawa Date: Sat, 28 Apr 2018 18:01:51 +0900 Subject: [PATCH] fix(challenges): Edit Description, Add Tests and Solution for Project Euler 40 (#17087) Updated the problem description to more closely match the one on the Project Euler page. Also added more tests along with a solution that user @elliotjz contributed to the fCC Arcade Mode. BREAKING CHANGE: None --- .../project-euler-problems.json | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 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 8e1fd80aee..06d03ba59e 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 @@ -1465,24 +1465,26 @@ "type": "bonfire", "title": "Problem 40: Champernowne's constant", "tests": [ - "assert.strictEqual(euler40(), 210, 'message: euler40() should return 210.');" + "assert.strictEqual(champernownesConstant(100), 5, 'message: champernownesConstant(100) should return 5.');", + "assert.strictEqual(champernownesConstant(1000), 15, 'message: champernownesConstant(1000) should return 15.');", + "assert.strictEqual(champernownesConstant(1000000), 210, 'message: champernownesConstant(1000000) should return 210.');" ], - "solutions": [], + "solutions": ["function champernownesConstant(n) {\n let fractionalPart = '';\n for (let i = 0; fractionalPart.length <= n; i++) {\n fractionalPart += i.toString();\n }\n\n let product = 1;\n for (let i = 0; i < n.toString().length; i++) {\n const index = 10 ** i;\n product *= parseInt(fractionalPart[index], 10);\n }\n\n return product;\n}"], "translations": {}, "challengeSeed": [ - "function euler40() {", + "function champernownesConstant(n) {", " // Good luck!", " return true;", "}", "", - "euler40();" + "champernownesConstant(100);" ], "description": [ "An irrational decimal fraction is created by concatenating the positive integers:", - "0.123456789101112131415161718192021...", - "It can be seen that the 12th digit of the fractional part is 1.", - "If dn represents the nth digit of the fractional part, find the value of the following expression.", - "d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000" + "0.123456789101112131415161718192021...", + "It can be seen that the 12th digit of the fractional part is 1.", + "If dn represents the nth digit of the fractional part, find the value of the following expression.", + "d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000" ] }, {