A Plague of Rabbits
I have a terrible rabbit problem.
I used to have a pair of baby rabbits; they were extremely cute and fluffy, so of course I got them. But the shopkeeper I get them from – a guy named Leonardo, of Pisa Pets – didn’t tell me they would mature very fast, and breed even faster.
After a month, I had a mature pair of rabbits… and, of course, they bred. Damn.
So, a month later, I had a pair of adults and a pair of baby rabbits.
And a month later, I had two pairs of adults, and another pair of baby rabbits,
And a month later, I had three pairs of adults, and two pairs of baby rabbits.
And a month later, I had five pairs of adults, and three pairs of baby rabbits.
HELP! I HAVE SO MANY RABBITS, I’M GOING HOPPING MAD!
I know that the number of rabbits I have each month will be the number of rabbits I had in the previous month, plus the number of rabbits I had in the month before.
Given I started with, well, no rabbits, and I got one pair of baby rabbits, write a function that tells me how many rabbits I’ll have after months. Give it this prototype:
long long rabbits (long long month);
(Hint: .)
To run some simple automated tests:
$ 1511 autotest rabbits
To run Styl-o-matic:
$ 1511 stylomatic rabbits.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk12_rabbits
Or, if you are working from home, upload the relevant file(s) to the wk12_rabbits activity on Give Online.