Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^6: Project Euler (a series of challenging mathematical/computer programming problems)

by BrowserUk (Patriarch)
on Feb 04, 2006 at 19:39 UTC ( [id://528027]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^5: Project Euler (a series of challenging mathematical/computer programming problems)
in thread Project Euler (a series of challenging mathematical/computer programming problems)

I just saw that and decided to time the mechanism I suggested. At 1/3rd of a second for the first million, it even surprised me :)

#! perl -slw use strict; use Devel::Timer; my $T = new Devel::Timer; sub firstNprimes { my $n = shift; open my $primes, '<:raw', 'primes.all' or die $!; my @primes = split ' ', do{ local $/ = \( $n * 10 ); <$primes> }; close $primes; return \@primes; } $T->mark( '201' ); my $ref1 = firstNprimes( 201 ); $T->mark( '100,000' ); my $ref2 = firstNprimes( 100_000 ); $T->mark( '1,000,000' ); my $ref3 = firstNprimes( 1_000_000 ); $T->report; __END__ C:\Perl\test\data>..\junk4 Devel::Timer Report -- Total time: 0.3176 secs Interval Time Percent ---------------------------------------------- 02 -> 03 0.3169 99.78% 100,000 -> 1,000,000 01 -> 02 0.0007 0.21% 201 -> 100,000 00 -> 01 0.0000 0.01% INIT -> 201

That's the ascii version, and it does slow down quite quickly due memory allocation as you go larger; 2 million takes 8 seconds.

I might try the binary file version later.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^6: Project Euler (a series of challenging mathematical/computer programming problems)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://528027]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.