我正在尝试修改斐波那契凡人兔子的 python 代码,以便根据兔子的年龄来改变兔子的繁殖力。让我们举个例子。
我的兔子在 3 个月后成熟,在 6 个月后死亡。在 4 个月的繁殖力期间,它们会根据年龄产生不同数量的后代。3个月大的时候生产2对兔子,4个月大的时候生产3对兔子,以此类推,直到第6个月。每对兔子由雌性和雄性组成。最后,我会计算配对的数量而不是个人的数量。从出生到死亡的繁殖力值:
fecundity = [0, 0, 2, 3, 3, 1]
我正在使用的 python 代码(https://github.com/jschendel/Rosalind/blob/master/011_FIBD.py)是:
n = 12
m = 6
#n = months to run
#m = how many months the rabbits live
# Populate the initial rabbits.
Rabbits = [1]+[0]*(m-1)
# Calculate the new rabbits (bunnies), in a given month.
# Start at use range(1,n) since our initial population is 0 month old.
for month in range(1, n):
Bunnies = 0
# Get the number of Rabbits able to old enough to give birth.
for j in range(1,m):
Bunnies += Rabbits[(month-j-1)%m]
# Bunnies replace the old rabbits who died.
Rabbits[(month)%m] = Bunnies
# Total rabbits is the sum of the living rabbits.
Total_Rabbits = sum(Rabbits)
我不确定如何实现繁殖力的变化。任何帮助表示赞赏!
谢谢你,瓦伦蒂娜