$i++;while(@p<50){$i++;&d;print"$i,"x!$x}sub d{for(@p){if($x=(!($i%$_))){return}}push@p,$i} [download]
Hello Schmunzie,
Nice! I like the way you’ve used the x operator. By removing the subroutine I was able to golf it down to this:
for($i=2;@p<50;++$i){$x=!!($i%$_)or goto _ for@p;push@p,$i;_:print"$i, +"x$x} [download]
16 characters saved, plus a C-style for loop and a goto! Bwahaha!
D’oh! Don’t know how I missed that. This one (77 characters) does print 2:
for($i=2;@p<50;++$i){($x=!($i%$_))&&goto _ for@p;push@p,$i;_:print"$i, +"x!$x} [download]
Cheers,
See also prime factorization using base 1 which suggests
print"$_,"x(1x$_)!~/^(11+)\1+$/ for 2..232 [download]
Which is not a Sieve! But then the OP's proposal is neither...
Update: this is a sieve (specify sieve size on command line):
$_=";"x(pop);s;.;.;;$;=~s:.:.:g,s:($;).:$1.:g,s,($;).,$1:,while($;)=m: +(.+?);:;s;:;1+pos();ge;say [download]
www.com | www.net | www.org
Cold Temperate Warm Hot Other
Results (70 votes). Check out past polls.