Skip to content

Instantly share code, notes, and snippets.

@prendradjaja
Last active December 28, 2021 19:21
Show Gist options
  • Save prendradjaja/6f95c1fba819814d2288617102da3656 to your computer and use it in GitHub Desktop.
Save prendradjaja/6f95c1fba819814d2288617102da3656 to your computer and use it in GitHub Desktop.
'use block' examples

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment