Home Segments Index Top Previous Next

235: Mainline

Here is a look at the function rabbits at work on 3, the same argument previously used with recursive_power_of_2. The value returned is the number of rabbits at the end of the third month.

Arguments     | ^      Returned values 
            3 | |  3   
              v | 
           *-------------* 
           | First call  | 
           *-------------* 
              | ^    |  ^ 
            2 | |  1 |  *------------* 
              | |    *-------------* | 
              v | 2                v | 1 
           *-------------*   *-------------* 
           | Second call |   | Fifth call  | 
           *-------------*   *-------------* 
              | ^    |  ^ 
            1 | |  0 |  *------------* 
              | |    *-------------* | 
              v | 1                v | 1 
           *-------------*   *-------------* 
           | Third call  |   | Fourth call | 
           *-------------*   *-------------*