Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Not a Sieve

by Schmunzie (Sexton)
on Mar 16, 2015 at 10:51 UTC ( #1120170=obfuscated: print w/replies, xml ) Need Help??

$i++;while(@p<50){$i++;&d;print"$i,"x!$x}sub d{for(@p){if($x=(!($i%$_))){return}}push@p,$i}

Replies are listed 'Best First'.
Re: The Sieve
by Athanasius (Chancellor) on Mar 16, 2015 at 14:16 UTC

    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}

    16 characters saved, plus a C-style for loop and a goto! Bwahaha!

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Love it! I didn't know that goto existed in Perl. Oh what fun to be had. Now all we need is ALTER from COBOL (anyone remember that?)
      Oops, at the risk of being picky, your solution doesn't print 2.
Also not a sieve
by ambrus (Abbot) on Mar 16, 2015 at 15:55 UTC

      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
        It's not. Hm.. gotta write a real one now.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://1120170]
Approved by Athanasius
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2017-12-16 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (449 votes). Check out past polls.

    Notices?