Cody

Solution 2266868

Submitted on 9 May 2020 by Nikolaos Nikolaou
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
n = 6; y = goldbach3(n); y_correct = [2,2,2]; assert(isequal(y,y_correct))

y = 2 2 2

2   Pass
n = 7; y = goldbach3(n); y_correct = [2,2,3]; assert(isequal(y,y_correct))

y = 2 2 3

3   Pass
n = 8; y = goldbach3(n); y_correct = [2,3,3]; assert(isequal(y,y_correct))

y = 2 3 3

4   Pass
n = 9; y = goldbach3(n); y_correct1 = [2,2,5]; y_correct2 = [3,3,3]; assert(isequal(y,y_correct1)|isequal(y,y_correct2))

y = 3 3 3

5   Pass
n = 10; y = goldbach3(n); y_correct = [2,3,5]; assert(isequal(y,y_correct))

y = 2 3 5

6   Pass
n = 11; y = goldbach3(n); y_correct1 = [2,2,7]; y_correct2 = [3,3,5]; assert(isequal(y,y_correct1)|isequal(y,y_correct2))

y = 2 2 7

7   Pass
n = 12; y = goldbach3(n); y_correct1 = [2,3,7]; y_correct2 = [2,5,5]; assert(isequal(y,y_correct1)|isequal(y,y_correct2))

y = 2 5 5

8   Pass
n = 13; y = goldbach3(n); y_correct1 = [3,3,7]; y_correct2 = [3,5,5]; assert(isequal(y,y_correct1)|isequal(y,y_correct2))

y = 3 5 5

9   Pass
n = 14; y = goldbach3(n); y_correct = [2,5,7]; assert(isequal(y,y_correct))

y = 2 5 7

10   Pass
n = 15; y = goldbach3(n); y_correct1 = [2,2,11]; y_correct2 = [3,5,7]; y_correct3 = [5,5,5]; assert(isequal(y,y_correct1)|isequal(y,y_correct2)|isequal(y,y_correct3))

y = 2 2 11

11   Pass
n = 101; y = goldbach3(n); assert(isequal(y,sort(y))) assert(all(isprime(y))) assert(sum(y)==n)

y = 11 23 67

12   Pass
n = 102; y = goldbach3(n); assert(isequal(y,sort(y))) assert(all(isprime(y))) assert(sum(y)==n)

y = 2 47 53

13   Pass
for n = 250:300 y = goldbach3(n); assert(isequal(y,sort(y))); assert(all(isprime(y))); assert(sum(y)==n); end

y = 2 19 229 y = 37 83 131 y = 2 83 167 y = 67 83 103 y = 2 41 211 y = 3 13 239 y = 2 103 151 y = 41 67 149 y = 2 29 227 y = 19 59 181 y = 2 29 229 y = 41 47 173 y = 2 109 151 y = 29 43 191 y = 2 29 233 y = 5 67 193 y = 2 127 137 y = 61 97 109 y = 2 67 199 y = 71 71 127 y = 2 41 227 y = 3 41 227 y = 2 113 157 y = 3 113 157 y = 2 109 163 y = 61 101 113 y = 2 83 191 y = 31 109 137 y = 2 47 229 y = 73 79 127 y = 2 7 271 y = 17 101 163 y = 2 23 257 y = 13 59 211 y = 2 109 173 y = 73 103 109 y = 2 73 211 y = 13 137 137 y = 2 3 283 y = 17 61 211 y = 2 131 157 y = 37 61 193 y = 2 7 283 y = 23 59 211 y = 2 41 251 y = 43 103 149 y = 2 37 257 y = 29 71 197 y = 2 103 193 y = 67 101 131 y = 2 107 191

14   Pass
n = randi(2000)+5; % generate a random integer greater than 5 and smaller than 2006 y = goldbach3(n); assert(isequal(y,sort(y))) assert(all(isprime(y))) assert(sum(y)==n)

y = 3 101 283

15   Pass
valid = zeros(1,50); for k = 1:50 n = randi(1000)+5; % generate a random integer greater than 5 and smaller than 1006 yk = goldbach3(n); valid(k) = (isequal(yk,sort(yk)) & all(isprime(yk)) & sum(yk)==n); end assert(all(valid));

y = 2 241 421 y = 73 103 269 y = 61 257 577 y = 37 257 263 y = 2 151 277 y = 31 103 233 y = 3 251 331 y = 2 257 389 y = 17 241 673 y = 83 89 523 y = 149 173 397 y = 17 41 491 y = 2 41 131 y = 19 113 251 y = 2 41 47 y = 2 277 521 y = 19 37 167 y = 193 233 233 y = 2 197 229 y = 2 43 547 y = 2 13 149 y = 17 79 331 y = 7 71 109 y = 2 3 3 y = 19 31 521 y = 83 359 463 y = 2 83 137 y = 2 167 373 y = 2 17 59 y = 2 71 317 y = 11 41 593 y = 11 67 179 y = 2 11 941 y = 2 67 269 y = 7 67 313 y = 5 31 101 y = 2 283 317 y = 2 109 691 y = 2 103 367 y = 101 139 653 y = 41 263 691 y = 3 61 389 y = 2 311 353 y = 2 197 239 y = 17 179 347 y = 2 109 487 y = 2 43 53 y = 2 47 677 y = 2 103 433 y = 103 109 113