Cody

Problem 1394. Prime Ladders

Solution 3274233

Submitted on 19 Oct 2020 by Paul Morant
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
p1 = 13; p2 = 29; ladder = prime_ladder(p1,p2); assert(all(isprime(ladder))) assert(iscolumn(ladder)) assert(ladder(1)==p1) assert(ladder(end)==p2) assert(all(sum(diff(num2str(ladder))~=0,2)==1))

fs = '%02d' y = 20 4 y = 20 4 1 ladder = 13 19 29

2   Pass
p1 = 389; p2 = 269; ladder = prime_ladder(p1,p2); assert(all(isprime(ladder))) assert(iscolumn(ladder)) assert(ladder(1)==p1) assert(ladder(end)==p2) assert(all(sum(diff(num2str(ladder))~=0,2)==1))

fs = '%03d' y = 104 45 y = 104 45 11 y = 104 45 11 2 y = 104 45 11 2 1 ladder = 389 383 283 263 269

3   Pass
p1 = 761; p2 = 397; ladder = prime_ladder(p1,p2); assert(all(isprime(ladder))) assert(iscolumn(ladder)) assert(ladder(1)==p1) assert(ladder(end)==p2) assert(all(sum(diff(num2str(ladder))~=0,2)==1))

fs = '%03d' y = 136 57 y = 136 57 16 y = 136 57 16 4 y = 136 57 16 4 1 ladder = 761 751 757 797 397

4   Pass
p1 = 983; p2 = 239; ladder = prime_ladder(p1,p2); assert(all(isprime(ladder))) assert(iscolumn(ladder)) assert(ladder(1)==p1) assert(ladder(end)==p2) assert(all(sum(diff(num2str(ladder))~=0,2)==1))

fs = '%03d' y = 64 20 y = 64 20 4 y = 64 20 4 1 ladder = 983 283 233 239

5   Pass
p1 = 271; p2 = 439; ladder = prime_ladder(p1,p2); assert(all(isprime(ladder))) assert(iscolumn(ladder)) assert(ladder(1)==p1) assert(ladder(end)==p2) assert(all(sum(diff(num2str(ladder))~=0,2)==1))

fs = '%03d' y = 160 96 y = 160 96 30 y = 160 96 30 7 y = 160 96 30 7 1 ladder = 271 71 79 479 439

6   Pass
p1 = 877; p2 = 733; ladder = prime_ladder(p1,p2); assert(all(isprime(ladder))) assert(iscolumn(ladder)) assert(ladder(1)==p1) assert(ladder(end)==p2) assert(all(sum(diff(num2str(ladder))~=0,2)==1))

fs = '%03d' y = 152 86 y = 152 86 30 y = 152 86 30 7 y = 152 86 30 7 1 ladder = 877 677 673 773 733

7   Pass
p1 = 2267; p2 = 1153; ladder = prime_ladder(p1,p2); assert(all(isprime(ladder))) assert(iscolumn(ladder)) assert(ladder(1)==p1) assert(ladder(end)==p2) assert(all(sum(diff(num2str(ladder))~=0,2)==1))

fs = '%04d' y = 1155 712 y = 1155 712 238 y = 1155 712 238 55 y = 1155 712 238 55 10 y = 1155 712 238 55 10 2 y = 1155 712 238 55 10 2 1 ladder = 2267 2269 2069 2063 2053 2153 1153

Suggested Problems

More from this Author50

Community Treasure Hunt

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

Start Hunting!