Cody

# Problem 3016. Twin Primes

Solution 2815042

Submitted on 10 Aug 2020 by Athi
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 = 1:5; twins_corr = [3, 5, 11, 17, 29; 5, 7, 13, 19, 31]; assert(isequal(twin_primes(n),twins_corr))

2   Pass
n = 1:10; twins_corr = [3, 5, 11, 17, 29, 41, 59, 71, 101, 107; 5, 7, 13, 19, 31, 43, 61, 73, 103, 109]; assert(isequal(twin_primes(n),twins_corr))

3   Pass
n = 1:25; twins_corr = [3, 5, 11, 17, 29, 41, 59, 71, 101, 107, 137, 149, 179, 191, 197, 227, 239, 269, 281, 311, 347, 419, 431, 461, 521; 5, 7, 13, 19, 31, 43, 61, 73, 103, 109, 139, 151, 181, 193, 199, 229, 241, 271, 283, 313, 349, 421, 433, 463, 523]; assert(isequal(twin_primes(n),twins_corr))

4   Pass
n = 1:51; twins_corr = [3, 5, 11, 17, 29, 41, 59, 71, 101, 107, 137, 149, 179, 191, 197, 227, 239, 269, 281, 311, 347, 419, 431, 461, 521, 569, 599, 617, 641, 659, 809, 821, 827, 857, 881, 1019, 1031, 1049, 1061, 1091, 1151, 1229, 1277, 1289, 1301, 1319, 1427, 1451, 1481, 1487, 1607; 5, 7, 13, 19, 31, 43, 61, 73, 103, 109, 139, 151, 181, 193, 199, 229, 241, 271, 283, 313, 349, 421, 433, 463, 523, 571, 601, 619, 643, 661, 811, 823, 829, 859, 883, 1021, 1033, 1051, 1063, 1093, 1153, 1231, 1279, 1291, 1303, 1321, 1429, 1453, 1483, 1489, 1609]; assert(isequal(twin_primes(n),twins_corr))

5   Pass
n = 10:29; twins_corr = [107, 137, 149, 179, 191, 197, 227, 239, 269, 281, 311, 347, 419, 431, 461, 521, 569, 599, 617, 641; 109, 139, 151, 181, 193, 199, 229, 241, 271, 283, 313, 349, 421, 433, 463, 523, 571, 601, 619, 643]; assert(isequal(twin_primes(n),twins_corr))

6   Pass
n = 2:8; twins_corr = [5, 11, 17, 29, 41, 59, 71; 7, 13, 19, 31, 43, 61, 73]; assert(isequal(twin_primes(n),twins_corr))

7   Pass
n = 35:42; twins_corr = [881, 1019, 1031, 1049, 1061, 1091, 1151, 1229; 883, 1021, 1033, 1051, 1063, 1093, 1153, 1231]; assert(isequal(twin_primes(n),twins_corr))

8   Pass
n = 34:47; twins_corr = [857, 881, 1019, 1031, 1049, 1061, 1091, 1151, 1229, 1277, 1289, 1301, 1319, 1427; 859, 883, 1021, 1033, 1051, 1063, 1093, 1153, 1231, 1279, 1291, 1303, 1321, 1429]; assert(isequal(twin_primes(n),twins_corr))

9   Pass
n = 9:-1:4; twins_corr = [101, 71, 59, 41, 29, 17; 103, 73, 61, 43, 31, 19]; assert(isequal(twin_primes(n),twins_corr))

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!