Name: Anonymous 2012-09-04 13:05
What the hell is going on in this line (taken from the first example here http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Perl):
>next if $tested[$j++];
This is incrementing the number somehow but I have no idea HOW. My first thought was that it was testing if there existed a number in the position after this one and then moving to the next pass of the while loop if that was true. But if that's the case, then how does it ever increment?
So my new thinking is that, based on other stuff I'm finding online and playing around with it, this is incrementing $j to ($j+1), creating $tested[$j+1] in the process. Then, if $tested[$j] has a number in it, it moves on to the next pass of the loop. If it doesn't have a number in $tested[$j], then it pushes $j onto the primes list? Do I have this right?
So what this whole thing really means is, if there's a 1 in $tested, that means that position's corresponding number has already been evaluated to be not-a-prime, because it's a multiple of some other number. Is that right?
>next if $tested[$j++];
This is incrementing the number somehow but I have no idea HOW. My first thought was that it was testing if there existed a number in the position after this one and then moving to the next pass of the while loop if that was true. But if that's the case, then how does it ever increment?
So my new thinking is that, based on other stuff I'm finding online and playing around with it, this is incrementing $j to ($j+1), creating $tested[$j+1] in the process. Then, if $tested[$j] has a number in it, it moves on to the next pass of the loop. If it doesn't have a number in $tested[$j], then it pushes $j onto the primes list? Do I have this right?
So what this whole thing really means is, if there's a 1 in $tested, that means that position's corresponding number has already been evaluated to be not-a-prime, because it's a multiple of some other number. Is that right?