Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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 ( [id://886011]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
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

    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://886011]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found