Cody

Problem 1394. Prime Ladders

Solution 3048196

Submitted on 3 Oct 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   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))

n = 1 pat = 1×3 string array "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))

n = 2 pat = 1×5 string array "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))

n = 2 pat = 1×5 string array "761" "461" "467" "367" "397"

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

n = 2

Matrix dimensions must agree. Error in prime_ladder (line 16) if sum(s1==s2)==n Error in Test4 (line 3) ladder = prime_ladder(p1,p2);

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

n = 2 pat = 1×6 string array "271" "211" "311" "331" "431" "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))

n = 2 pat = 1×5 string array "877" "677" "673" "773" "733"

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

n = 3

Matrix dimensions must agree. Error in prime_ladder (line 16) if sum(s1==s2)==n Error in Test7 (line 3) ladder = prime_ladder(p1,p2);

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!