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.
|
---|