Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Commit 58e82ea

Browse files
scissorsneedfoodtoomstellaluna
authored andcommitted
fix(challenges): Edit Description, Add Tests and Solution for Project Euler 47 (#17142)
Edited the description to more closely match the spacing and line breaks from projecteuler.net. Added more tests, updated the challenge seed, and added a solution from user @elliotjz contributed to the fCC Arcade Mode. BREAKING CHANGE: None
1 parent b7be885 commit 58e82ea

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,23 +1661,28 @@
16611661
"type": "bonfire",
16621662
"title": "Problem 47: Distinct primes factors",
16631663
"tests": [
1664-
"assert.strictEqual(euler47(), 134043, 'message: <code>euler47()</code> should return 134043.');"
1664+
"assert.strictEqual(distinctPrimeFactors(2, 2), 14, 'message: <code>distinctPrimeFactors(2, 2)</code> should return 14.');",
1665+
"assert.strictEqual(distinctPrimeFactors(3, 3), 644, 'message: <code>distinctPrimeFactors(3, 3)</code> should return 644.');",
1666+
"assert.strictEqual(distinctPrimeFactors(4, 4), 134043, 'message: <code>distinctPrimeFactors(4, 4)</code> should return 134043.');"
16651667
],
1666-
"solutions": [],
1668+
"solutions": ["function distinctPrimeFactors(targetNumPrimes, targetConsecutive) {\n\n function isPrime(num) {\n for (let i = 2, s = Math.sqrt(num); i <= s; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return num !== 1;\n }\n\n function getPrimeFactors(num) {\n const factors = [];\n for (let i = 2; i <= Math.sqrt(num); i++) {\n if (num % i === 0) {\n // found a factor\n if (isPrime(i)) {\n factors.push(i);\n }\n if (isPrime(num / i) && i !== Math.sqrt(num)) {\n factors.push(num / i);\n }\n }\n }\n return factors;\n }\n\n function findConsecutiveNumbers() {\n let number = 0;\n let consecutive = 0;\n while (consecutive < targetConsecutive) {\n number++;\n if (getPrimeFactors(number).length >= targetNumPrimes) {\n consecutive++;\n } else {\n consecutive = 0;\n }\n }\n return (number - targetConsecutive) + 1;\n }\n\n return findConsecutiveNumbers();\n }"],
16671669
"translations": {},
16681670
"challengeSeed": [
1669-
"function euler47() {",
1671+
"function distinctPrimeFactors(targetNumPrimes, targetConsecutive) {",
16701672
" // Good luck!",
16711673
" return true;",
16721674
"}",
16731675
"",
1674-
"euler47();"
1676+
"distinctPrimeFactors(4, 4);"
16751677
],
16761678
"description": [
16771679
"The first two consecutive numbers to have two distinct prime factors are:",
1678-
"14 = 2 × 715 = 3 × 5",
1680+
"<div style='padding-left: 4em;'>14 = 2 × 7</div>",
1681+
"<div style='padding-left: 4em;'>15 = 3 × 5</div>",
16791682
"The first three consecutive numbers to have three distinct prime factors are:",
1680-
"644 = 2² × 7 × 23645 = 3 × 5 × 43646 = 2 × 17 × 19.",
1683+
"<div style='padding-left: 4em;'>644 = 2² × 7 × 23</div>",
1684+
"<div style='padding-left: 4em;'>645 = 3 × 5 × 43</div>",
1685+
"<div style='padding-left: 4em;'>646 = 2 × 17 × 19</div>",
16811686
"Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?"
16821687
]
16831688
},

0 commit comments

Comments
 (0)