https://github.com/prendradjaja/advent-of-code-2021/blob/main/20--trench-map/a.py
def step(self, rules):
self.pixels = use self, rules:
new_pixels = [[None] * self.outer_width for _ in range(self.outer_height)]
for r, row in enumerate(self.pixels):
for c, _ in enumerate(row):
neighborhood_value = self.neighborhood_value((r, c))
new_pixels[r][c] = rules[neighborhood_value]
return new_pixels
background = self.background
self.background = use background, rules:
assert background in '.#'
key = 0 if background == '.' else 511
return rules[key]
def step(self, rules):
new_pixels = [[None] * self.outer_width for _ in range(self.outer_height)]
for r, row in enumerate(self.pixels):
for c, _ in enumerate(row):
neighborhood_value = self.neighborhood_value((r, c))
new_pixels[r][c] = rules[neighborhood_value]
self.pixels = new_pixels
assert self.background in '.#'
key = 0 if self.background == '.' else 511
self.background = rules[key]