Cody

# Problem 3016. Twin Primes

Solution 2683304

Submitted on 12 Jul 2020 by pign_an
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))

twins = 3 5 11 17 29 5 7 13 19 31

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))

twins = 3 5 11 17 29 41 59 71 101 107 5 7 13 19 31 43 61 73 103 109

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))

twins = 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

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))

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

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))

twins = 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

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))

twins = 5 11 17 29 41 59 71 7 13 19 31 43 61 73

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))

twins = 881 1019 1031 1049 1061 1091 1151 1229 883 1021 1033 1051 1063 1093 1153 1231

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))

twins = 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

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))

twins = 101 71 59 41 29 17 103 73 61 43 31 19

### Community Treasure Hunt

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

Start Hunting!