N=63 r=range(N) f=[[" "for i in r]for i in r] f[N/2][N/2]="X" while 1: w=0 for x in r: for y in r: c=0 for i in range(-1,2): for j in range(-1,2): if 0<=x+i<N and 0<=y+j<N and f[y+j][x+i]=="X":c+=1 if c==1 and f[y][x]!="X":f[y][x]="x";w=1 for j in r: for i in r: if f[j][i]=="x":f[j][i]="X" if w==0:break for x in f:print "".join(x)
Note that non-ascii characters in the above source code will be escaped (such as \x9f).