in reply to Re: Prime list
in thread Prime list

And, of course, the classic regex approach:

c:\@Work\Perl\monks>perl -wMstrict -le "my @primes; ;; for (my $i = 2; @primes < 10; ++$i) { push @primes, $i if ('x' x $i) !~ m{ \A (..+) \1+ \z }xms; } ;; print qq{@primes}; " 2 3 5 7 11 13 17 19 23 29


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^3: Prime list
by LanX (Saint) on Feb 08, 2015 at 22:49 UTC
    Maybe a nice educational example to explain, how \1 backreference and backtracking in regex work... not so much for primes though.

    Homework wise I mean! ;-)

    Cheers Rolf

    PS: Je suis Charlie!

      But it's such a deliciously scandalous (ab)use of the RE that I had to throw it in! And in any event, a student's reach should exceed his or her grasp...


      Give a man a fish:  <%-(-(-(-<

Re^3: Prime list
by QM (Parson) on Feb 09, 2015 at 11:04 UTC
    I love this one. Thanks for throwing it up again.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of