interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / wireworld / oracle.py

14 lines · 720 bytes Raw Blame History
1# Independent reference for "Wireworld" (Python 3, standard library only).
2# expected.txt is this program's stdout; omc never produced it.
3rows = ["tH.........", ". . ", " ... ", ". . ", "Ht.. ......"]
4def step(g):
5 def heads(r, c):
6 return sum(1 for dr in (-1, 0, 1) for dc in (-1, 0, 1)
7 if (dr or dc) and 0 <= r + dr < len(g) and 0 <= c + dc < len(g[0]) and g[r + dr][c + dc] == "H")
8 nxt = {"H": "t", "t": ".", " ": " "}
9 return ["".join(nxt.get(ch) or ("H" if heads(r, c) in (1, 2) else ".") for c, ch in enumerate(row))
10 for r, row in enumerate(g)]
11for gen in range(10):
12 print("generation", gen)
13 print("\n".join(rows))
14 rows = step(rows)