Home Segments Index Top Previous Next

326: Mainline

Capturing the rabbit formula in the form of a Smalltalk method, you have the following definition for rabbits:

Integer method definition • instance 
rabbits 
  (self = 0 or: [self = 1]) 
    ifTrue: [^ 1] 
    ifFalse: [^ (self - 1) rabbits + (self - 2) rabbits] 
Workspace
Transcript  
  show: 'After month 1, there is '  ;  
  show: 1  rabbits printString; cr; 
  show: 'After month 2, there are ' ; 
  show: 2  rabbits printString; cr; 
  show: 'After month 3, there are '  ; 
  show: 3  rabbits printString; cr; 
  show: 'After month 4, there are '  ;  
  show: 4  rabbits printString; cr; 
  show: 'After month 5, there are '  ;  
  show: 5  rabbits printString; cr; 
  show: 'After month 24, there are ' ;  
  show: 24 rabbits printString; cr 
Transcript 
After month 1, there is 1 
After month 2, there are 2 
After month 3, there are 3 
After month 4, there are 5 
After month 5, there are 8 
After month 24, there are 75025 

Evidently, at the end of 2 years, your book sales will be extremely healthy if those sales grow like rabbits.