Cody

# Problem 42749. Find the nearest prime

Solution 1604136

Submitted on 8 Aug 2018
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   Fail
n = 3; y_correct = 3; assert(isequal(closestPrime(n),y_correct))

Error using isprime (line 19) All entries of X must be nonnegative integers. Error in closestPrime (line 3) a=a(isprime(a)); Error in Test1 (line 3) assert(isequal(closestPrime(n),y_correct))

2   Fail
n = 20; y_correct = 23; assert(isequal(closestPrime(n),y_correct))

Error using isprime (line 19) All entries of X must be nonnegative integers. Error in closestPrime (line 3) a=a(isprime(a)); Error in Test2 (line 3) assert(isequal(closestPrime(n),y_correct))

3   Fail
n = 86; y_correct = 89; assert(isequal(closestPrime(n),y_correct))

Error using isprime (line 19) All entries of X must be nonnegative integers. Error in closestPrime (line 3) a=a(isprime(a)); Error in Test3 (line 3) assert(isequal(closestPrime(n),y_correct))

4   Pass
n = 250; y_correct = 251; assert(isequal(closestPrime(n),y_correct))

ans = 251