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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The speed of the is_prime function can be increase by about 140% by using the 2 4 trick used below.
sub is_prime { my %prime = map { $_ => 1 } (2, 3, 5, 7); my %not_prime; return sub { my $n = shift; return 1 if $prime{ $n }; return 0 if $n % 2 == 0 || $n % 3 == 0 || exists $not_prime{ $n }; my $last = int sqrt $n; for ( my $x = 5; $x <= $last ;) { return $not_prime{ $n } = 0 if $n % $x == 0; $x += 2; return $not_prime{ $n } = 0 if $n % $x == 0; $x += 4; } return $prime{ $n } = 1; }; }
This version skips all of the numbers that are divisable by 2 and 3. Not checking numbers divisable by 2 is obvious, but not checking numbers divisable by 3 is less so, but reduces the search space by 25%.

In reply to Re^2: a close prime number by gam3
in thread a close prime number by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Discipulus]: M4ver1k are you debug/dump vars in the loops? are you sure you are not quitting the loop earlier?
    [Corion]: A good weekstart to everybody!
    [Discipulus]: good morning nuns and monks! hello Corion

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (6)
    As of 2017-11-20 08:09 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (285 votes). Check out past polls.