Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics

Dashboard
Notifications
Mark all as read
Challenges

Solve Goldbach's Conjecture

+5
−0

Goldbach's Conjecture states that every even whole number greater than 2 is the sum of 2 prime numbers. Your task is to return those 2 prime numbers, given an even whole number as input. There are often multiple solutions - any solution will do.

Input/Output Examples

These examples only show one of potentially many possible outputs.

4 -> 2, 2
6 -> 3, 3
24 -> 5, 19
120 -> 7, 113
1000 -> 3, 997

This is code golf, so shortest answer in each language wins.

P.S. If no one finds a test case that has no solution, I'll consider the problem solved by engineer's induction.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comments

2 answers

+1
−0

JavaScript (Node.js), 87 bytes

f=(a,b=2,c=a-b,d=(a,b=2)=>b<a?a%b&&d(a,b+1):1,e=a=>d(++a)?a:e(a))=>d(c)?[b,c]:f(a,e(b))

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comments

+0
−0

Husk, 9 bytes

ḟo=⁰Σπ2İp

Try it online!

Explanation

ḟo=⁰Σπ2İp
       İp take the infinite list of primes
     π2   cartesian power 2 (all possible pairs)
ḟo        first pair which satisfies:
    Σ     sum
  =       equals
   ⁰      input?
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comments

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!