From 831c6a6e158e55f60beff5322f578f1e6125f95d Mon Sep 17 00:00:00 2001 From: Kristofer Koishigawa Date: Sat, 28 Apr 2018 18:00:38 +0900 Subject: [PATCH] fix(challenges): Edit Description and Add Solution for Project Euler 33 (#17085) Updated the problem description with and tags. Also added a solution that user @elliotjz contributed to the fCC Arcade Mode. BREAKING CHANGE: None --- .../project-euler-problems.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 2c968a0a9b..c26d3c3f3c 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 @@ -1276,21 +1276,21 @@ "type": "bonfire", "title": "Problem 33: Digit cancelling fractions", "tests": [ - "assert.strictEqual(euler33(), 100, 'message: euler33() should return 100.');" + "assert.strictEqual(digitCancellingFractions(), 100, 'message: digitCancellingFractions() should return 100.');" ], - "solutions": [], + "solutions": ["function digitCancellingFractions() {\n function isCurious(numerator, denominator) {\n const fraction = numerator / denominator;\n const numString = numerator.toString();\n const denString = denominator.toString();\n\n if (numString[1] === '0' && denString[1] === '0') {\n // trivial\n return false;\n }\n for (let i = 0; i < 2; i++) {\n for (let j = 0; j < 2; j++) {\n if (numString[i] === denString[j]) {\n const newNum = parseInt(numString[1 - i], 10);\n const newDen = parseInt(denString[1 - j], 10);\n if (newNum / newDen === fraction) {\n return true;\n }\n }\n }\n }\n return false;\n }\n function findLargestDivisor(a, b) {\n let gcd = a > b ? b : a;\n while (gcd > 1) {\n if (a % gcd === 0 && b % gcd === 0) {\n return gcd;\n }\n gcd--;\n }\n return gcd;\n }\n\n function simplifyFraction(numerator, denominator) {\n const divisor = findLargestDivisor(numerator, denominator);\n return [numerator / divisor, denominator / divisor];\n }\n\n let multipleNumerator = 1;\n let multipleDenominator = 1;\n\n for (let denominator = 11; denominator < 100; denominator++) {\n for (let numerator = 10; numerator < denominator; numerator++) {\n if (isCurious(numerator, denominator)) {\n multipleNumerator *= numerator;\n multipleDenominator *= denominator;\n }\n }\n }\n\n return simplifyFraction(multipleNumerator, multipleDenominator)[1];\n}"], "translations": {}, "challengeSeed": [ - "function euler33() {", + "function digitCancellingFractions() {", " // Good luck!", " return true;", "}", "", - "euler33();" + "digitCancellingFractions();" ], "description": [ - "The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.", - "We shall consider fractions like, 30/50 = 3/5, to be trivial examples.", + "The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.", + "We shall consider fractions like, 30/50 = 3/5, to be trivial examples.", "There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.", "If the product of these four fractions is given in its lowest common terms, find the value of the denominator." ]