![]() |
![]() |
![]() |
![]() |
![]() |
|
In Segment 349, you learned that the number of rabbits after
more than 1 month is the sum of the number at the end of the previous
month and the month before that. With only this information, you can
rewrite the rabbits function in terms of two auxiliary functions,
previous_month and penultimate_month:
int rabbits (int n) {
if (n == 0 || n == 1)
return 1;
else return previous_month (n) + penultimate_month (n);
}
Then, realizing that previous_month must return the number of
rabbits at the end of the previous month, you can see that you can
define previous_month as follows:
int previous_month (int n) {return rabbits (n - 1);}
Analogous reasoning leads you to the following definition for
penultimate_month:
int penultimate_month (int n) {return rabbits (n - 2);}