Hey ;)
Could you please comment on my solution? I see the size is much larger than leading solution, but regardless. I would say my solution is lame, because it was taylored for this specific set of conditions (test suite), I would like to make "universal" solution, which could work for random inputs, but this taylored solution seems much easier. What do you think?
Thank you for your opinion :)
Try setting up a loop to test individual values using isprime() that will terminate upon reaching the fifth prime number to prevent an inordinately long loop.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
n_min = 60;
n_max = 1000;
y_correct = [151,157,251,257,353];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
2 | Pass |
n_min = 60;
n_max = 300;
y_correct = -1;
assert(isequal(five_primes(n_min,n_max),y_correct))
|
3 | Pass |
n_min = 1;
n_max = 200;
y_correct = [5,53,59,151,157];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
4 | Pass |
n_min = 1;
n_max = 100;
y_correct = -1;
assert(isequal(five_primes(n_min,n_max),y_correct))
|
5 | Pass |
n_min = 500;
n_max = 600;
y_correct = [503,509,521,523,541];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
6 | Pass |
n_min = 500;
n_max = 555;
y_correct = [503,509,521,523,541];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
7 | Pass |
n_min = 500;
n_max = 500000000;
y_correct = [503,509,521,523,541];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
8 | Pass |
n_min = 5000;
n_max = 5020;
y_correct = -1;
assert(isequal(five_primes(n_min,n_max),y_correct))
|
9 | Pass |
n_min = 5000;
n_max = 5200;
y_correct = [5003,5009,5011,5021,5023];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
10 | Pass |
n_min = 5000;
n_max = 55555555;
y_correct = [5003,5009,5011,5021,5023];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
11 | Pass |
n_min = 55555;
n_max = 56789;
y_correct = [55579,55589,55603,55609,55619];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
12 | Pass |
n_min = 987654321;
n_max = 988777666;
y_correct = [987654323,987654337,987654347,987654359,987654361];
assert(isequal(five_primes(n_min,n_max),y_correct))
|
Return the largest number that is adjacent to a zero
3750 Solvers
536 Solvers
686 Solvers
Are all the three given point in the same line?
270 Solvers
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
511 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!