Suppose I start with one pair of rabbit and each pair reproduces 3 pairs of rabbits.
Let new rabbit pair be N
and mature rabbit pair be M
:
N 0
M 1
MNNN 4
MNNN MMM MMM MMM 19
So the series is 0 1 4 19
How do we do this on Python using loops:
I tried:
x="N" #new rabbit pair
x=x.replace("N","M")
x
'M' #Mature rabbit pair
x=x.replace("M","MNNN")
x
'MNNN'
x=x.replace("M","MN")
x=x.replace("N","M")
x
'MNNNMMM'
How do I put this in a loop using xrange/range function.
Thanks
The process for a single step is to replace all
'M'
s with'MNNN'
and all'N'
s with'M'
, so:For example: