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:
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.
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!
594 Solvers
269 Solvers
260 Solvers
Make an identity matrix whose diagonal elements are 1:n
42 Solvers
Matrix element wise multiplication
42 Solvers