omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / wireworld / oracle.py
| 1 | # Independent reference for "Wireworld" (Python 3, standard library only). |
| 2 | # expected.txt is this program's stdout; omc never produced it. |
| 3 | rows = ["tH.........", ". . ", " ... ", ". . ", "Ht.. ......"] |
| 4 | def 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)] |
| 11 | for gen in range(10): |
| 12 | print("generation", gen) |
| 13 | print("\n".join(rows)) |
| 14 | rows = step(rows) |