Although the naming of primes is a poor choice,
primes = primes(nums);
can replace:
nums=2:n;
primes=nums(isprime(nums));
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
nList = 28:6:76;
for i = 1:length(nList)
n = nList(i);
[p1,p2] = goldbach(n)
assert(isprime(p1) && isprime(p2) && (p1+p2==n));
end
p1 =
5
p2 =
23
p1 =
3
p2 =
31
p1 =
3
p2 =
37
p1 =
3
p2 =
43
p1 =
5
p2 =
47
p1 =
5
p2 =
53
p1 =
3
p2 =
61
p1 =
3
p2 =
67
p1 =
3
p2 =
73
|
2 | Pass |
%%
nList = [18 20 22 100 102 114 1000 2000 36 3600];
for i = 1:length(nList)
n = nList(i);
[p1,p2] = goldbach(n)
assert(isprime(p1) && isprime(p2) && (p1+p2==n));
end
p1 =
5
p2 =
13
p1 =
3
p2 =
17
p1 =
3
p2 =
19
p1 =
3
p2 =
97
p1 =
5
p2 =
97
p1 =
5
p2 =
109
p1 =
3
p2 =
997
p1 =
3
p2 =
1997
p1 =
5
p2 =
31
p1 =
7
p2 =
3593
|
1398 Solvers
Maximum running product for a string of numbers
1112 Solvers
Back to basics 4 - Search Path
321 Solvers
376 Solvers
277 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!