Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 292082

Submitted on 30 Jul 2013

Incorrect

30Size
Leading solution size is 3.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, log in.

Test Suite

Test
Code Input and Output
1
Pass
 
feval(@assignin,'caller','score',30); %

                    
2
Fail
 
%%
tic
assert(isequal(primes_faster(1),primes(1)))
assert(isequal(primes_faster(2),primes(2)))
for i=1:100
 n=randi(2000,1);
 assert(isequal(primes_faster(n),primes(n)))
end
toc
Error: Output argument "z" (and maybe others) not assigned during call to "/users/msssystem3/primes_faster.m>primes_faster".
3
Fail
 
%%
tic
ta=clock;
 p = primes_faster(2^28);
t1=etime(clock,ta); % time in sec
fprintf('P 2^28 %12i %10.3f\n',length(p),t1)
assert(isequal(size(unique(p),2),14630843))
ptr=randi(7603553,1,10); % small to avoid timeout
pchk=p(ptr);
assert(all(isprime(pchk)))
feval(  @assignin,'caller','score',floor(min(30,t1))  );
toc
Error: Out of memory. Type HELP MEMORY for your options.