Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by davido (Cardinal)
on Feb 02, 2011 at 20:16 UTC ( [id://885845]=note: print w/replies, xml ) Need Help??


in reply to A script with a loop is running my computer Out of memory

By the way. One thing I noticed and forgot to mention. You are making the assumption that each generation has up to 5 offspring. That means each couple must have up to 10, or each woman up to 10... or that both men and women can bare offspring of up to 5 each.

Is this a worm population growth chart?

;)


Dave

  • Comment on Re: A script with a loop is running my computer Out of memory

Replies are listed 'Best First'.
Re^2: A script with a loop is running my computer Out of memory
by Lady_Aleena (Priest) on Feb 03, 2011 at 14:07 UTC

    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

      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

Log In?
Username:
Password:

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

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

    No recent polls found