FunctionRacerProblemsRace

Wireworld Step

EasyGridsPython, JavaScript, TypeScript, Java, C++

grid is a circuit in the Wireworld cellular automaton, given as a list of equal-length strings, one per row. Each character is . (empty), H (electron head), t (electron tail) or # (copper wire). All cells change at the same time, by these rules: an empty cell stays empty; a head becomes a tail; a tail becomes wire; a wire cell becomes a head if exactly one or two of its eight neighbours (the cells sharing a side or a corner with it) are heads, and otherwise stays wire. Cells outside the grid count as empty. Return the grid after one step, in the same format, without changing grid.

Example 1

grid ["#tH##"]
returns ["##tH#"]

The electron moves one cell to the right: the head becomes a tail, the old tail becomes wire, and the wire just after the head touches exactly one head.

Example 2

grid ["HHH",".#.","#.#"]
returns ["ttt",".#.","#.#"]

The three heads become tails. The middle wire touches three heads, which is too many, so it stays wire, and the bottom wires touch no head at all.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems