Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: (Golf): Sieve of Eratosthenes

by MeowChow (Vicar)
on May 19, 2001 at 20:54 UTC ( #81734=note: print w/replies, xml ) Need Help??


in reply to (Golf): Sieve of Eratosthenes

How about this at 45 (strict compliant too):
sub sieve { sub p{$_[0],@_?p(grep$_%$_[0],@_):()}p 2..pop }
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Re: (Golf): Sieve of Eratosthenes
by chipmunk (Parson) on May 19, 2001 at 21:54 UTC
    I think that undef is not prime. :)

    But at 47 characters I think MeowChow still won't be beat:

    sub sieve { sub p{$_[0],@_>1?p(grep$_%$_[0],@_):()}p 2..pop }
      I had thought of that, but assumed it would slide :)

      Make that 46 by the way...

      sub sieve { sub p{$_[0],$#_?p(grep$_%$_[0],@_):()}p 2..pop }
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
        I had thought of that, but that goes into deep recursion if you call sieve(1). :)

        Oh, but tilly says that you may assume $n is above a fixed number. Pooh!

      Abusing the rules for fun and profit (46 chars):
      sub sieve { sub p{$_[0],@_>1?p(grep$_%$_[0],@_):1}p 2..pop }
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
Re (tilly) 2: (Golf): Sieve of Eratosthenes
by tilly (Archbishop) on May 19, 2001 at 21:27 UTC
    Unless someone improves on this I think I know who is getting the t-shirt for the main problem. If anyone comes within 5 characters of beating my solution - HAH! How about if anyone completely trashes the best I could do..?

    Of course the bonus question is still wide open...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://81734]
help
Chatterbox?
[Corion]: :-D
Corion discovers a new shiny toy to try out over the (longish) weekend. Since I've done some more with websockets, maybe I'll try writing a webserver that implements hot-reloading of HTML(+CSS, +Javascript) in the browser. Edit the local file and ...
[Corion]: ... the browser(s) get a ping to a) refresh the page or b) reload "just" the changed parts, keeping the scroll position etc.
[Corion]: But I also have to look at how I can make WWW::Mechanize:: RemoteBrowser a reality, and how to make it safe from malicious content ;)
[Corion]: Part of wanting hot-reloading is that I think I've stumbled on a very simple set of CSS that I maybe want to use for a blog, but I want to try that out on mobile too, and I also want to add/modify it slightly so it has a header too...
[Corion]: ... and having hot reloading would make it easy to view the changes in multiple browser windows of different sizes, and on Android, simultaneously

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2018-04-26 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?