Problem 44403. Goldbach's marginal conjecture - Write integer as sum of three primes
Goldbach's strong conjecture states that every even integer greater than 2 can be expressed as the sum of two primes. For example: 4 = 2+2, 6 = 3+3, 8 = 3+5, 10 = 3+7 = 5+5, 12 = 5+7 etc.
As a corrollary, Goldbach's weak conjecture states that every odd integer greater than 7 can be expressed as the sum of three odd primes. For example: 9 = 3+3+3, 11 = 3+3+5, 13 = 3+3+7 = 3+5+5, 15 = 3+5+7 = 5+5+5 etc.
A third conjecture was written by Goldbach in the margin of a letter, and (in its modern version) states that
" Every integer greater than 5 can be expressed as the sum of three primes. "
Examples:
- 6 = 2 + 2 + 2
- 7 = 2 + 2 + 3
- 8 = 2 + 3 + 3
- 9 = 2 + 2 + 5 = 3 + 3 + 3
- 10 = 2 + 3 + 5
- 11 = 2 + 2 + 7 = 3 + 3 + 5
- 12 = 2 + 3 + 7 = 2 + 5 + 5
- 13 = 3 + 3 + 7 = 3 + 5 + 5
- 14 = 2 + 5 + 7
- 15 = 2 + 2 + 11 = 3 + 5 + 7 = 5 + 5 + 5
Your task is to write a function which takes a positive integer n as input, and which returns a 1-by-3 vector y, which contains three numbers that are primes and whose sum equals n. If there exist multiple solutions for y, then any one of those solutions will suffice. However, y must be in sorted order. You can assume that n will be an integer greater than 5.
Solution Stats
Problem Comments
-
2 Comments
Hi, yurenchu. Nice problem, and you have constructed a nicely comprehensive Test Suite. However, could you please assess the two submissions to check whether the Test Suite might be missing some valid possible triplets? (I know the first submission shouldn't pass, because I accidentally omitted one command, but I think the second submission should pass.) There is also a misprint of "y-correct" instead of "y_correct" in test number 9. Thanks, DIV.
Hi David Verelli. Thanks a lot for your comments regarding my first created problem, I really appreciate it. Sorry for not replying any sooner, but my computer broke down a few days ago. Thanks for discovering the flaws and errors in the test suite. A few of the tests were indeed missing valid solution triplets, I've fixed them now. I've also fixed the spelling error in test #9 and a problem with the random integer selection. Your solution should pass now (I don't know how long rescoring will take)! Again, thanks a lot for your feedback, much appreciated!
Solution Comments
Show commentsProblem Recent Solvers61
Suggested Problems
-
Back to basics 23 - Triangular matrix
980 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
601 Solvers
-
Find the maximum number of decimal places in a set of numbers
2768 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1046 Solvers
-
4097 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!