|
1661 | 1661 | "type": "bonfire",
|
1662 | 1662 | "title": "Problem 47: Distinct primes factors",
|
1663 | 1663 | "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.');" |
1665 | 1667 | ],
|
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 }"], |
1667 | 1669 | "translations": {},
|
1668 | 1670 | "challengeSeed": [
|
1669 |
| - "function euler47() {", |
| 1671 | + "function distinctPrimeFactors(targetNumPrimes, targetConsecutive) {", |
1670 | 1672 | " // Good luck!",
|
1671 | 1673 | " return true;",
|
1672 | 1674 | "}",
|
1673 | 1675 | "",
|
1674 |
| - "euler47();" |
| 1676 | + "distinctPrimeFactors(4, 4);" |
1675 | 1677 | ],
|
1676 | 1678 | "description": [
|
1677 | 1679 | "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>", |
1679 | 1682 | "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>", |
1681 | 1686 | "Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?"
|
1682 | 1687 | ]
|
1683 | 1688 | },
|
|
0 commit comments