Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: A script with a loop is running my computer Out of memory

by GrandFather (Saint)
on Feb 03, 2011 at 19:49 UTC ( [id://886055]=note: print w/replies, xml ) Need Help??


in reply to Re^3: A script with a loop is running my computer Out of memory
in thread A script with a loop is running my computer Out of memory

Or by modifying the compound interest formula to kill off the previous generation:

use strict; use warnings; my $startPop = 4; my $targetPop = 250e9; my $increase = 2.5; my $n = int ((log($targetPop) - log($startPop)) / log($increase) + 0.5 +); my $pop = int ($startPop * ($increase) ** $n); print "$pop population after $n generations\n";

Prints:

222044604925 population after 27 generations

Add 1 instead of 0.5 in the $n calculation if you want a minimum of $targetPop.

True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://886055]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2024-04-25 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found