in reply to Re: 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

The assumption is that into each generation is born a certain number of children, and those children have a certain number of children, etc. Gender is not being taken into account, and the children's spouses are not being tallied here. And no, this is not a worm population growth chart. I am just trying to get an idea of how many generations it would take to get to about 250 billion people born into it, give or take a couple billion. I haven't taken interbreeding into account either, as after about a 5 generation gap some consider it safe to interbreed though some consider sooner than that safe. Doing that however would add yet even more complexity that I haven't even tried to think about adding.

Have a cookie and a very nice day!
Lady Aleena
  • Comment on Re^2: A script with a loop is running my computer Out of memory

Replies are listed 'Best First'.
Re^3: A script with a loop is running my computer Out of memory
by jdporter (Paladin) on Feb 03, 2011 at 15:48 UTC

    Look, if you know the generational growth rate (i.e. for each person in generation N, there are 2.5 people in generation N+1, or whatever), then just start with your 250 billion and work backwards. (2.5 is the average of rand(6).)

    $n = 250_000_000_000; $a = 2.5; while ($n>2) { print "$n\n"; $n /= $a; } ^D 250000000000 100000000000 40000000000 16000000000 6400000000 2560000000 1024000000 409600000 163840000 65536000 26214400 10485760 4194304 1677721.6 671088.64 268435.456 107374.1824 42949.67296 17179.869184 6871.9476736 2748.77906944 1099.511627776 439.8046511104 175.92186044416 70.368744177664 28.1474976710656 11.2589990684262 4.5035996273705

    There. 28 generations.

    Approximately.

      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