Programming cats

Have you ever wondered how many cats you would have if you started with just one female and left it alone with males for 5 years?

No? Nor had I… Until this morning!

I connected to the IdleMonkeys IRC server and was greeted by the following statement from Zach:

Did you know that 1 female cat not spayed will produce in 5 years, through her offspring and their offspring and their offspring etc. etc. 700,000!

I thought this sounded high, and so Zach and I did a few pointless calculations before I got the idea to write a script that would simulate this whole thing. I started out by writing a module to represent a cat. I called it Cat.pm and it looks like this:

package Cat;
use strict;
use base qw(Class::Accessor::Fast);
Cat->mk_accessors(qw(gender age pregnant pregnant_days gestation_period days_since_litter sexual_maturity));

1;

Very simply it defines a few values like the age and gender of a cat. Thanks to Class:Accessor::Fast I can easily get and set these values in my main script using something like this:

my $cat = Cat->new({ gender => 'Male', age => 0''});

Or

$cat->gender('Female');
$cat->age(12); #Age in days

I did a bunch of “research” (thanks Wikipedia) on the reproductive habits of the common house cat and found the ranges to configure for the gestation period, age of sexual maturity, etc. etc. It turns out that a female cat can be sexually mature at 5 months old, and can give birth around 2 months later. Cats tend to mate for 9 months of the year, skipping winter. After giving birth to around 3-5 kittens most cats have a period of at least around a month where they don’t get pregnant again, although it could be a lot longer. Zach asked me to specify that 60% of the cats born in a litter be female. I have no figures to suggest this is accurate, but I went with it anyway.

I programmed the first version of my script before I knew all of those facts and arrived at a number of around 5 million cats after 5 years of breeding. This was obviously ridiculous, and so I revised my script a few times.

With all the information I gathered I came up with a much lower figure than either of the previous ones. Over 10 runs of the script the average number of cats after 5 years was 16492.4. I ran the script through 1000 complete iterations and generated an average for all runs. The script took 3 hours 38 minutes and 15 seconds to execute and calculated an average of 10400.693 cats. ๐Ÿ™‚

There are a few problems with this script:

  • The first major problem is that there is no notion of males breeding with any females that are not descendants of the first cat. If other non-related females were around then the number would be significantly higher, as the males would be able to mate with all of them, and would produce a huge increase in numbers. So, this whole thing assumes that there is only one female cat in the entire world when the script starts running.
  • The script assumes that the first cat is born right at the beginning of the breeding season. If that changes then the figures would probably be quite different.
  • The script assumes that a cat will become pregnant exactly 30 days after giving birth to the previous litter (assuming it is within the breeding season).

Obviously there are many other shortcomings, but there will always be some when simulating any sort of behaviour like this.