Miscellany
public text v1 · immutablesieve(int max) {
// Arrays are indexed starting with 0
primes = dynamic array of int, initial length 0;
checked = array of bool, length max-1, initially false;
for x from 2 to max {
if checked[x-2] // the number 2 is the 0th element of checked
then next;
else {append x to primes;
for y from x to max step 2 { // goes through x, 2x, 3x, etc.
checked[y-2] = true;}
}
return primes;
}