day 24
lobby layout
approach
each line is split into hex directions (e, w, and the two-letter ne, nw, se, sw) and walked on axial coordinates: a hex grid stored as two integers, where each of the six directions changes r, c or both by one. tiles are flipped by toggling their coordinate in a set of black tiles, and part 1 is the size of that set.
part 2 runs a hex version of the game of life for 100 days. each step counts black neighbours for every tile adjacent to a black one; black tiles stay black with 1 or 2 black neighbours, and white tiles with exactly 2 turn black.
the trick
axial coordinates turn the hex grid into ordinary 2d integer pairs with six fixed neighbour offsets.
python
def neighbors(r, c):
yield r + 1, c - 1
yield r + 1, c
yield r, c - 1
yield r - 1, c
yield r - 1, c + 1
yield r, c + 1