interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / langtons-ant / oracle.py

21 lines · 937 bytes Raw Blame History
1# Independent reference for "Langton's ant" (Python 3, standard library only).
2# expected.txt is this program's stdout; omc never produced it.
3# the black cells as a set; the heading as a complex number (up = -1j with rows growing downward)
4black = set()
5pos, head = complex(50, 50), -1j # real part = column, imaginary part = row
6steps = 0
7while 0 <= pos.real < 100 and 0 <= pos.imag < 100:
8 if pos in black:
9 head *= -1j # left turn
10 black.remove(pos)
11 else:
12 head *= 1j # right turn
13 black.add(pos)
14 pos += head
15 steps += 1
16print("steps until the ant leaves the grid:", steps)
17rows = [int(p.imag) for p in black]
18cols = [int(p.real) for p in black]
19print(f"black cells, rows and columns {min(rows)}..{max(rows)} {min(cols)}..{max(cols)}")
20for r in range(min(rows), max(rows) + 1):
21 print("".join("#" if complex(c, r) in black else "." for c in range(min(cols), max(cols) + 1)))