From 58e82ea802d9e0acbb6c1c379cea80c42778151c Mon Sep 17 00:00:00 2001 From: Kristofer Koishigawa Date: Sat, 12 May 2018 11:15:55 +0900 Subject: [PATCH] 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 --- .../project-euler-problems.json | 17 +++++++++++------ 1 file changed, 11 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 7269204b1f..598005e081 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 @@ -1661,23 +1661,28 @@ "type": "bonfire", "title": "Problem 47: Distinct primes factors", "tests": [ - "assert.strictEqual(euler47(), 134043, 'message: euler47() should return 134043.');" + "assert.strictEqual(distinctPrimeFactors(2, 2), 14, 'message: distinctPrimeFactors(2, 2) should return 14.');", + "assert.strictEqual(distinctPrimeFactors(3, 3), 644, 'message: distinctPrimeFactors(3, 3) should return 644.');", + "assert.strictEqual(distinctPrimeFactors(4, 4), 134043, 'message: distinctPrimeFactors(4, 4) should return 134043.');" ], - "solutions": [], + "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 }"], "translations": {}, "challengeSeed": [ - "function euler47() {", + "function distinctPrimeFactors(targetNumPrimes, targetConsecutive) {", " // Good luck!", " return true;", "}", "", - "euler47();" + "distinctPrimeFactors(4, 4);" ], "description": [ "The first two consecutive numbers to have two distinct prime factors are:", - "14 = 2 × 715 = 3 × 5", + "
14 = 2 × 7
", + "
15 = 3 × 5
", "The first three consecutive numbers to have three distinct prime factors are:", - "644 = 2² × 7 × 23645 = 3 × 5 × 43646 = 2 × 17 × 19.", + "
644 = 2² × 7 × 23
", + "
645 = 3 × 5 × 43
", + "
646 = 2 × 17 × 19
", "Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?" ] },