in reply to Streams and "deep recursion" warning
Just a side note... this is quite slow.
With the following code (you can see that it is raw and not tweaked for performance), it took 1 second to find the 2000th (17389):
use Data::Dumper; use strict; use warnings; print time(), "\n"; my @primes; my $candidate = 2; while ($#primes < $ARGV[0] - 1) { my $found = 0; while (!$found) { for my $prime (@primes) { if (!($candidate % $prime)) { $found = 1; last; } } if (!$found) { push @primes, $candidate; } $candidate ++; } } print $primes[-1], "\n"; print time(), "\n";
With the Stream one, it took 140 seconds.
|
|---|