Problem
Recall the definition of the Fibonacci numbers from “Rabbits and Recurrence Relations”, which followed the recurrence relation
Our aim is to somehow modify this recurrence relation to achieve a dynamic programming solution in the case that all rabbits die out after a fixed number of months. See Figure 4 for a depiction of a rabbit tree in which rabbits live for three months (meaning that they reproduce only twice before dying).
Given: Positive integers
Return: The total number of pairs of rabbits that will remain after the
month = 83
lifespan = 19
cycle = [0] * lifespan
cycle[0] = 1
for i in range(month-1):
temp = 0
for j in range(lifespan-1, 0, -1):
temp = temp + cycle[j]
cycle[j] = cycle[j-1]
cycle[0] = temp
print(sum(cycle))
Wabbit Season
In “Rabbits and Recurrence Relations”, we mentioned the disaster caused by introducing European rabbits into Australia. By the turn of the 20th Century, the situation was so out of control that the creatures could not be killed fast enough to slow their spread (see Figure 1).
The conclusion? Build a fence! The fence, intended to preserve the sanctity of Western Australia, was completed in 1907 after undergoing revisions to push it back as the bunnies pushed their frontier ever westward (see Figure 2). If it sounds like a crazy plan, the Australians at the time seem to have concurred, as shown by the cartoon in Figure 3.
By 1950, Australian rabbits numbered 600 million, causing the government to decide to release a virus (called myxoma) into the wild, which cut down the rabbits until they acquired resistance. In a final Hollywood twist, another experimental rabbit virus escaped in 1991, and some resistance has already been observed.
The bunnies will not be stopped, but they don't live forever, and so in this problem, our aim is to expand Fibonacci's rabbit population model to allow for mortal rabbits.
'Python > rosaland' 카테고리의 다른 글
Calculating Expected Offspring (0) | 2018.12.07 |
---|---|
Overlap Graphs (0) | 2018.12.07 |
Consensus and Profile (0) | 2018.12.05 |
Combing Through the Haystack (0) | 2018.11.30 |
Translating RNA into Protein (0) | 2018.11.30 |