def decode(keypad): keypad = ZGrid(keypad) z = keypad.z("5") code = "" for line in data.splitlines(): for direction in line: dz = getattr(ZGrid, direction) if keypad.get(z + dz, " ").strip(): z += dz code += keypad[z] return code
def test_square(): grid = ZGrid(minibeam) expected = grid.z("O") grid.translate({".": 0, "O": 1, "#": 1}) z = q19.locate_square(beam=grid.get, width=10, hi=grid.height) assert z == 25 + 20j == expected