Cody

Solution 2186812

Submitted on 1 Apr 2020
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
x = 0; y_correct = 2; assert(isequal(nearestprime(x),y_correct))

X = 0 0 y = 0 0 t = 1×2 logical array 0 0 X = -1 1

Error using isprime (line 19) All entries of X must be nonnegative integers. Error in nearestprime (line 5) t = isprime(X) Error in Test1 (line 3) assert(isequal(nearestprime(x),y_correct))

2   Pass
x = 5; y_correct = 5; assert(isequal(nearestprime(x),y_correct))

X = 5 5 y = 0 0 t = 1×2 logical array 1 1 y = 5 5 y = 5 y = 5

3   Pass
x = 100; y_correct = 101; assert(isequal(nearestprime(x),y_correct))

X = 100 100 y = 0 0 t = 1×2 logical array 0 0 X = 99 101 t = 1×2 logical array 0 1 y = 0 101 t1 = 1×2 logical array 1 0 X = 98 101 t = 1×2 logical array 0 1 y = 0 101 t1 = 1×2 logical array 1 0 X = 97 101 t = 1×2 logical array 1 1 y = 97 101 y = 97 101 y = 101

4   Pass
x = 500; y_correct = 499; assert(isequal(nearestprime(x),y_correct))

X = 500 500 y = 0 0 t = 1×2 logical array 0 0 X = 499 501 t = 1×2 logical array 1 0 y = 499 0 t1 = 1×2 logical array 0 1 X = 499 502 t = 1×2 logical array 1 0 y = 499 0 t1 = 1×2 logical array 0 1 X = 499 503 t = 1×2 logical array 1 1 y = 499 503 y = 499 503 y = 499

5   Pass
x = 911; y_correct = 911; assert(isequal(nearestprime(x),y_correct))

X = 911 911 y = 0 0 t = 1×2 logical array 1 1 y = 911 911 y = 911 y = 911

6   Pass
x = 2500; y_correct = 2503; assert(isequal(nearestprime(x),y_correct))

X = 2500 2500 y = 0 0 t = 1×2 logical array 0 0 X = 2499 2501 t = 1×2 logical array 0 0 X = 2498 2502 t = 1×2 logical array 0 0 X = 2497 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2496 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2495 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2494 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2493 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2492 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2491 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2490 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2489 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2488 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2487 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2486 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2485 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2484 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2483 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2482 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2481 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2480 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2479 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2478 2503 t = 1×2 logical array 0 1 y = 0 2503 t1 = 1×2 logical array 1 0 X = 2477 2503 t = 1×2 logical array 1 1 y = 2477 2503 y = 2477 2503 y = 2503

7   Pass
x = 8000; y_correct = 7993; assert(isequal(nearestprime(x),y_correct))

X = 8000 8000 y = 0 0 t = 1×2 logical array 0 0 X = 7999 8001 t = 1×2 logical array 0 0 X = 7998 8002 t = 1×2 logical array 0 0 X = 7997 8003 t = 1×2 logical array 0 0 X = 7996 8004 t = 1×2 logical array 0 0 X = 7995 8005 t = 1×2 logical array 0 0 X = 7994 8006 t = 1×2 logical array 0 0 X = 7993 8007 t = 1×2 logical array 1 0 y = 7993 0 t1 = 1×2 logical array 0 1 X = 7993 8008 t = 1×2 logical array 1 0 y = 7993 0 t1 = 1×2 logical array 0 1 X = 7993 8009 t = 1×2 logical array 1 1 y = 7993 8009 y = 7993 8009 y = 7993

8   Pass
x = 100000; y_correct = 100003; assert(isequal(nearestprime(x),y_correct))

X = 100000 100000 y = 0 0 t = 1×2 logical array 0 0 X = 99999 100001 t = 1×2 logical array 0 0 X = 99998 100002 t = 1×2 logical array 0 0 X = 99997 100003 t = 1×2 logical array 0 1 y = 0 100003 t1 = 1×2 logical array 1 0 X = 99996 100003 t = 1×2 logical array 0 1 y = 0 100003 t1 = 1×2 logical array 1 0 X = 99995 100003 t = 1×2 logical array 0 1 y = 0 100003 t1 = 1×2 logical array 1 0 X = 99994 100003 t = 1×2 logical array 0 1 y = 0 100003 t1 = 1×2 logical array 1 0 X = 99993 100003 t = 1×2 logical array 0 1 y = 0 100003 t1 = 1×2 logical array 1 0 X = 99992 100003 t = 1×2 logical array 0 1 y = 0 100003 t1 = 1×2 logical array 1 0 X = 99991 100003 t = 1×2 logical array 1 1 y = 99991 100003 y = 99991 100003 y = 100003

9   Pass
x = 1300000; y_correct = 1299989; assert(isequal(nearestprime(x),y_correct))

X = 1300000 1300000 y = 0 0 t = 1×2 logical array 0 0 X = 1299999 1300001 t = 1×2 logical array 0 0 X = 1299998 1300002 t = 1×2 logical array 0 0 X = 1299997 1300003 t = 1×2 logical array 0 0 X = 1299996 1300004 t = 1×2 logical array 0 0 X = 1299995 1300005 t = 1×2 logical array 0 0 X = 1299994 1300006 t = 1×2 logical array 0 0 X = 1299993 1300007 t = 1×2 logical array 0 0 X = 1299992 1300008 t = 1×2 logical array 0 0 X = 1299991 1300009 t = 1×2 logical array 0 0 X = 1299990 1300010 t = 1×2 logical array 0 0 X = 1299989 1300011 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300012 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300013 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300014 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300015 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300016 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300017 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300018 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300019 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300020 t = 1×2 logical array 1 0 y = 1299989 0 t1 = 1×2 logical array 0 1 X = 1299989 1300021 t = 1×2 logical array 1 1 y = 1299989 1300021 y = 1299989 1300021 y = 1299989

10   Pass
x = 179424710; y_correct = 179424719; assert(isequal(nearestprime(x),y_correct))

X = 179424710 179424710 y = 0 0 t = 1×2 logical array 0 0 X = 179424709 179424711 t = 1×2 logical array 0 0 X = 179424708 179424712 t = 1×2 logical array 0 0 X = 179424707 179424713 t = 1×2 logical array 0 0 X = 179424706 179424714 t = 1×2 logical array 0 0 X = 179424705 179424715 t = 1×2 logical array 0 0 X = 179424704 179424716 t = 1×2 logical array 0 0 X = 179424703 179424717 t = 1×2 logical array 0 0 X = 179424702 179424718 t = 1×2 logical array 0 0 X = 179424701 179424719 t = 1×2 logical array 0 1 y = 0 179424719 t1 = 1×2 logical array 1 0 X = 179424700 179424719 t = 1×2 logical array 0 1 y = 0 179424719 t1 = 1×2 logical array 1 0 X = 179424699 179424719 t = 1×2 logical array 0 1 y = 0 179424719 t1 = 1×2 logical array 1 0 X = 179424698 179424719 t = 1×2 logical array 0 1 y = 0 179424719 t1 = 1×2 logical array 1 0 X = 179424697 179424719 t = 1×2 logical array 1 1 y = 179424697 179424719 y = 179424697 179424719 y = 179424719