View on GitHub

Rabbits-Rabbits-Rabbits

CS 1400 Project 3

Project 3: Rabbits, Rabbits, Rabbits

Problem Statement

Suppose that a scientist is doing some important research work that requires her to use rabbits in her experiments. She starts out with one adult male rabbit and one adult female rabbit. At the end of each month, a pair of adult rabbits produces one pair of offspring, a male and a female. These new offspring will take one month to mature and become adults. The scientist has 500 cages in which to hold her rabbits. Each cage holds one pair of rabbits. Assuming that no rabbits ever die, when will she run out of cages?

To illustrate this, consider the first two months. At the beginning of month one, the scientist just has the original one pair of adult rabbits. A table for month one will look something like:

Month Adults Babies Total
1 1 0 1

At the end of month one this pair of adults produces one pair of offspring. Thus, at the beginning of month two the table will look like this:

Month Adults Babies Total
1 1 0 1
2 1 1 2

At the end of month two the adults have another pair of baby rabbits. The first pair of babies, born at the end of last month are not old enough to have babies yet, but we will categorize them as adults. So, at the beginning of month three the table looks like this:

Month Adults Babies Total
1 1 0 1
2 1 1 2
3 2 1 3

Possible Algorithm

Directions

  1. Develop your algorithm in detail before writing any code. Read the problem statement closely several times. Make sure you understand all the small details.

  2. Open the exercise.py file in the src directory, and begin coding your solution.

  3. Test your program for accuracy by comparing your output to the example below.

  4. Format the output file exactly as shown in the example below:

     # Table of rabbit pairs
     Month, Adults, Babies, Total
     1, 1, 0, 1
     2, 1, 1, 2
     3, 2, 1, 3
     .
     .
     13, 233, 144, 377
     14, 377, 233, 610
     # Cages will run out in month 14
    
  5. Update the module docstring with your information.

Helpful Resource(s)