You are viewing a single comment's thread from:

RE: The Sieve of Eratosthenes: An Ancient Greek Method of Finding Primes

in #math6 years ago

This is a really cool method! Here is an implementation of it I put together in octave for a course earlier this year:

function [list] = primeList (n)

isPrime = ones(1,n); % one is not prime
isPrime(1,1) = 0;
list = [];

for i = 2:n
if(isPrime(1,i) == 1)
    list = horzcat(list,i);
    for j = (i^2):i:n
           isPrime(1,j) = 0;
    end
  end
end

end

Coin Marketplace

STEEM 0.27
TRX 0.12
JST 0.033
BTC 63091.31
ETH 3172.78
USDT 1.00
SBD 3.81