Nice! But the pedant in me feels compelled to point out that for a 35% increase in length, this obfu can be made significantly more time-efficient:

$m=250;print 2;for($b=3;$b<=$m;$b+=2){if(!$d[$a]){for($a=$b*$b;$a<=$m; +$a+=$b){$c[$a]=1}}print",$b"}

The speed increase is negligible for low values of $m, but for large value it becomes significant (e.g. an increase of nearly 8 times in speed for $m equal to ten million):

use strict; use warnings; use Benchmark qw(:all) ; my $m = 1e7; cmpthese ( 5, { Op => sub { op(); }, Ath => sub { ath(); }, } ); sub op { my @c; my $last = 2; for (2 .. $m) { for (my $a = $_ * 2; $a <= $m; $a += $_) { $c[$a]++ } $last = $_ if !$c[$_]; } print "$last\n"; } sub ath { my @d; my $last = 2; for (my $a = 3; $a <= $m; $a += 2) { next if $d[$a]; for (my $b = $a * $a; $b <= $m; $b += $a) { $d[$b]++ } $last = $a; } print "$last\n"; }

Output:

23:05 >perl 1205_Obfu.pl 9999991 9999991 9999991 9999991 9999991 9999991 9999991 9999991 9999991 9999991 s/iter Op Ath Op 62.2 -- -87% Ath 8.02 676% -- 23:11 >

But note that this version is still inefficient. See johngg’s recent post: Re^3: Number functions I have lying around, which saves on (1) cpu time by iterating only up to sqrt($m), and (2) memory by storing the sieve in a bit vector.

Hope this is of interest,

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


In reply to Re: This One's a Sieve by Athanasius
in thread This One's a Sieve by Schmunzie

Title:
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, details, 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, summary, 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.