fix(challenges): Edit Description and Add Solution for Project Euler 33 (#17085)
Updated the problem description with <sup> and <sub> tags. Also added a solution that user @elliotjz contributed to the fCC Arcade Mode. BREAKING CHANGE: Nonepull/18182/head
parent
048734def0
commit
831c6a6e15
|
@ -1276,21 +1276,21 @@
|
|||
"type": "bonfire",
|
||||
"title": "Problem 33: Digit cancelling fractions",
|
||||
"tests": [
|
||||
"assert.strictEqual(euler33(), 100, 'message: <code>euler33()</code> should return 100.');"
|
||||
"assert.strictEqual(digitCancellingFractions(), 100, 'message: <code>digitCancellingFractions()</code> 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 <sup>49</sup>/<sub>98</sub> is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that <sup>49</sup>/<sub>98</sub> = <sup>4</sup>/<sub>8</sub>, which is correct, is obtained by cancelling the 9s.",
|
||||
"We shall consider fractions like, <sup>30</sup>/<sub>50</sub> = <sup>3</sup>/<sub>5</sub>, 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."
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue