From 7235ca1def2c32528f8ca41ec6a32c416aec8941 Mon Sep 17 00:00:00 2001 From: Kristofer Koishigawa Date: Wed, 9 May 2018 04:53:01 +0900 Subject: [PATCH] fix(challenges): Edit Description and Add Solution for Project Euler 46 (#17140) Updated the problem description with `` tags. Also added a solution that user @elliotjz contributed to the fCC Arcade Mode. BREAKING CHANGE: None --- .../project-euler-problems.json | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 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 656c90bd57..7b8647be1f 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 @@ -1631,26 +1631,26 @@ "type": "bonfire", "title": "Problem 46: Goldbach's other conjecture", "tests": [ - "assert.strictEqual(euler46(), 5777, 'message: euler46() should return 5777.');" + "assert.strictEqual(goldbachsOtherConjecture(), 5777, 'message: goldbachsOtherConjecture() should return 5777.');" ], - "solutions": [], + "solutions": ["function goldbachsOtherConjecture() { function isPrime(num) {\n if (num < 2) {\n return false;\n } else if (num === 2) {\n return true;\n }\n const sqrtOfNum = Math.floor(num ** 0.5);\n for (let i = 2; i <= sqrtOfNum + 1; i++) {\n if (num % i === 0) {\n return false;\n }\n }\n return true;\n }\n\n function isSquare(num) {\n return Math.sqrt(num) % 1 === 0;\n }\n\n // construct a list of prime numbers\n const primes = [];\n for (let i = 2; primes.length < 1000; i++) {\n if (isPrime(i)) primes.push(i);\n }\n\n let num = 3;\n let answer;\n while (!answer) {\n num += 2;\n if (!isPrime(num)) {\n let found = false;\n for (let primeI = 0; primeI < primes.length && !found; primeI++) {\n const square = (num - primes[primeI]) / 2;\n if (isSquare(square)) {\n found = true;\n break;\n }\n }\n if (!found) answer = num;\n }\n }\n return answer;\n}"], "translations": {}, "challengeSeed": [ - "function euler46() {", + "function goldbachsOtherConjecture() {", " // Good luck!", " return true;", "}", "", - "euler46();" + "goldbachsOtherConjecture();" ], "description": [ "It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.", - "9 = 7 + 2×12", - "15 = 7 + 2×22", - "21 = 3 + 2×32", - "25 = 7 + 2×32", - "27 = 19 + 2×22", - "33 = 31 + 2×12", + "9 = 7 + 2×12", + "15 = 7 + 2×22", + "21 = 3 + 2×32", + "25 = 7 + 2×32", + "27 = 19 + 2×22", + "33 = 31 + 2×12", "It turns out that the conjecture was false.", "What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?" ]