% primes.m

% the efficient way
tic
for i = 2:1e4
    number_is_prime = true;
    if (mod(i,2)==0)
        number_is_prime = false;
    else
        for j = 2:floor(sqrt(i))
            if (mod(i,j)==0)
                number_is_prime = false;
                break
            end
        end
    end
    if (number_is_prime == true)
%        fprintf('%d is prime\n', i);
    end
end
toc

% the totally brute force inefficient way
tic
for i = 2:1e4
    number_is_prime = true;
    for j = 2:(i-1)
        if (mod(i,j)==0)
            number_is_prime = false;
        end
    end
    if (number_is_prime == true)
%        fprintf('%d is prime\n', i);
    end
end
