Code: Select all

```
# Collects statistics from neighbourhood counts.
# Author: NASZVADI P., 2016 Dec 12.
import golly as g
if g.empty():
if g.getwidth() == 0 or g.getheight() == 0:
g.exit("Senseless!")
else:
r = g.getrect()
if len(r) == 0:
g.exit("Senseless too!")
minx = r[0]
miny = r[1]
maxx = minx + r[2]
maxy = miny + r[3]
stats = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
def checkneighbour(x, y):
return g.getcell(x, y)+2*(g.getcell(x+1, y+1)+g.getcell(x+1, y-1)+g.getcell(x-1, y+1)+g.getcell(x-1, y-1)+g.getcell(x-1, y)+g.getcell(x, y-1)+g.getcell(x, y+1)+g.getcell(x+1, y))
def neighbourstats():
# main loop
for x in range(minx,maxx):
for y in range(miny,maxy):
stats[checkneighbour(x, y)] += 1
try:
neighbourstats()
finally:
resultall = ""
for j in range(9):
for i in [0,1]:
if i+j and stats[i+2*j]:
resultall += "[" + `i` + ", " + `j` + "] = " + `stats[i+2*j]` + "; "
g.show(" Results: " + resultall)
```