Wireworld Step
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
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
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
1 <= rows, cols <= 10- every row has the same length
- every character is
.,H,tor#
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Crush and FallMedium
- Four in a RowMedium
- Life-Like GenerationsMedium
- Minutes to BurnMedium
- Paths Around RocksMedium
- Ramp DropMedium
- Settle the SandpileMedium
- Slide and MergeMedium