Wabbit season

In "Rabbits and recurrence relations1", 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.

rabbit skins
A c.1905 photo from Australia of a cart loaded to the hilt with rabbit skins.

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 left figure below). If it sounds like a crazy plan, the Australians at the time seem to have concurred, as shown by the cartoon in the right figure below.

rabbit fence
Western Australia's rabbit fence is actually not the longest fence in the world as the sign claims. That honor goes to a 3,500 mile fence in southeastern Australia built to keep out dingoes. Courtesy Matt Pounsett.
rabbit tennis
An 1884 cartoon from the Queensland Figaro proposing how the rabbits viewed their fence.

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.

Assignment

Recall the definition of the Fibonacci numbers from "Rabbits and recurrence relations2", which followed the recurrence relation $$F_n = F_{n-1} + F_{n-2}$$ and assumed that each pair of rabbits reaches maturity in one month and produces a single pair of offspring (one male, one female) each subsequent month.

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 the figure below for a depiction of a rabbit tree in which rabbits live for three months (meaning that they reproduce only twice before dying).

mortal rabbit tree
A figure illustrating the propagation of Fibonacci's rabbits if they die after three months.

Write a function rabbits that takes two positive integers $$n$$ and $$m$$. The function must return the total number of rabbit pairs that will remain after $$n$$ months if all rabbits live for $$m$$ months.

Example

>>> rabbits(6, 3)
4
>>> rabbits(29, 2)
1
>>> rabbits(28, 5)
88412
>>> rabbits(29, 3)
2513
>>> rabbits(100, 20)
353368918335207375428