Last active
December 21, 2015 18:39
-
-
Save coleoguy/6348755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lifespan <- 18 | |
months <- 85 | |
pop <- vector(mode="numeric", length=months) # this will hold the population each month as we build it up | |
pop[1:2] <- 1 # rabbits take a month to mature so we go ahead and fill in month 1 and 2 | |
for(i in 3:months){ # this loop will just build our population month by month | |
if(i-(lifespan+1) < 0){ # if we are early on none have died yet this if statement takes care of that | |
pop[i] <- pop[i-1]+pop[i-2]-0 | |
} | |
if(i-(lifespan+1) == 0){ # this one takes care of the first rabbit dying | |
pop[i] <- pop[i-1]+pop[i-2]-1 | |
} | |
if(i-(lifespan+1) > 0){ # this handles all subsequent months | |
pop[i] <- pop[i-1]+pop[i-2]-pop[i-(lifespan+1)] | |
} | |
} | |
pop[months] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment