Code: Select all

```
import golly as g
import hashlib
magic_code = (0, 1, 2, 3, 4, 5, 6, 4, 6, 4, 3, 0, 1, 6, 5, 2)
sq4 = lambda x : magic_code[(x & 3) | ((x >> 1) & 12)]
sq9 = lambda y : (sq4(y), sq4(y >> 1), sq4(y >> 3), sq4(y >> 4))
if (g.numstates() != 2):
g.exit('Pattern must be 2-state.')
clist = g.getcells(g.getrect())
g.addlayer()
# Construct transition table:
for i in xrange(512):
x = 5 * (i & 31)
y = 5 * (i >> 5)
for u in xrange(3):
for v in xrange(3):
g.setcell(x + u, y + v, (i >> (3 * v + u)) & 1)
g.run(1)
tt = [g.getcell(5 * (i & 31) + 1, 5 * (i >> 5) + 1) for i in xrange(512)]
rulename = 'Moore2vn-' + hashlib.sha256(repr(tt)).hexdigest()[:12]
with open(g.getdir('rules') + rulename + '.rule', 'w') as f:
f.write('@RULE %s\n' % rulename)
f.write('@TABLE\nn_states:8\nneighborhood:vonNeumann\nsymmetries:none\n\n')
for i in xrange(16):
(a, b, c, d) = (i & 1, (i >> 1) & 1, (i >> 2) & 1, (i >> 3) & 1)
f.write('0%d%d%d%d%d\n' % (7*a, 7*b, 7*d, 7*c, magic_code[i]))
for i in xrange(512):
(a, b, c, d) = sq9(i)
f.write('0%d%d%d%d%d\n' % (a, b, d, c, 7 * tt[i]))
for i in xrange(8):
f.write('%d00000\n' % i)
g.new('Converted pattern')
g.setrule(rulename)
newcells = [(x-y, x+y, 7) for (x, y) in zip(clist[0::2], clist[1::2])]
newcells = [x for l in newcells for x in l]
if (len(newcells) % 2 == 0):
newcells += [0]
g.putcells(newcells)
g.fit()
```

*restricted*von Neumann neighbourhood, where a cell (x, y) can only exist at time t if (x, y, t) is even. Consequently, every live cell is always surrounded by 4 dead cells and always dies.

90% of the work in this script went into discovering the single line:

Code: Select all

`magic_code = (0, 1, 2, 3, 4, 5, 6, 4, 6, 4, 3, 0, 1, 6, 5, 2)`