Wednesday, November 20, 2013

Enter the first year when the fast wumpuses outnumber the slow wumpuses

We can use loops to simulate natural processes over time. Write a program that calculates the populations of two kinds of “wumpuses” over time. At the beginning of year 1, there are 1000 slow wumpuses and 1 fast wumpus. This one fast wumpus is a new mutation. Not surprisingly, being fast gives it an advantage, as it can better escape from predators. Each year, each wumpus has one offspring. (We'll ignore the more realistic niceties of sexual reproduction, like distinguishing males and females.). There are no further mutations, so slow wumpuses beget slow wumpuses, and fast wumpuses beget fast wumpuses. Also, each year 40% of all slow wumpuses die each year, while only 30% of the fast wumpuses do.
So, at the beginning of year one there are 1000 slow wumpuses. Another 1000 slow wumpuses are born. But, 40% of these 2000 slow wumpuses die, leaving a total of 1200 at the end of year one. Meanwhile, in the same year, we begin with 1 fast wumpus, 1 more is born, and 30% of these die, leaving 1.4. (We'll also allow fractional populations, for simplicity.)
Beginning of YearSlow WumpusesFast Wumpuses
110001
212001.4
314401.96
Enter the first year in which the fast wumpuses outnumber the slow wumpuses. Remember that the table above shows the populations at the start of the year.
slow_wumpuses, fast_wumpuses = 1000, 1
years=0
while slow_wumpuses > fast_wumpuses:
    slow_wumpuses *=.6*2
    fast_wumpuses *=.7*2
    years+=1
print "First year when the fast wumpuses outnumber the slow wumpuses : ", years
Output :
First year when the fast wumpuses outnumber the slow wumpuses :  45

3 comments:

  1. how in the world did you come up with:

    slow_wumpuses *=.6*2
    fast_wumpuses *=.7*2

    ??

    Can you please explain? I am having trouble with this excercise. The rest of it, I wrote it quite similarly to you.

    Thanks,

    Chris

    ReplyDelete
  2. Hi, 0.6 = 60% of population which is doubled each year, same with 0.7.

    ReplyDelete
  3. Real no deposit slot machines for players from New Zealand - play at this website

    ReplyDelete