diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-20 05:50:23 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-20 05:50:23 +0000 |
commit | d0085fa59347640e202a0f8c1ace272406caa7f0 (patch) | |
tree | 8e493973d88bea3117ff1922af89d4789d3fcd93 | |
parent | 8e251ba55bd1e07bc4107782a1f9c4bc780beeb7 (diff) | |
download | aoc2021-d0085fa59347640e202a0f8c1ace272406caa7f0.tar.gz aoc2021-d0085fa59347640e202a0f8c1ace272406caa7f0.tar.xz aoc2021-d0085fa59347640e202a0f8c1ace272406caa7f0.zip |
day 20: cleanup
-rw-r--r-- | 20.py | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -5,16 +5,17 @@ img = dict() with open_day(20) as f: first, rest = f.read().rstrip().split('\n\n') alg = [c == '#' for c in first] + assert(len(alg) == 512) for y, line in enumerate(rest.split('\n')): for x, c in enumerate(line): img[(x, y)] = c == '#' def bits_at(img, x, y): bits = [] - for dx, dy in ((-1, -1), (0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1), (1, 1)): - bits.append(img.get((x + dx, y + dy), bg)) - val = int(''.join('1' if b else '0' for b in bits), 2) - return val + for dy in range(-1, 2): + for dx in range(-1, 2): + bits.append(img.get((x + dx, y + dy), bg)) + return sum(b * 2 ** i for i, b in enumerate(reversed(bits))) def iter(): global bg, img @@ -32,11 +33,7 @@ def iter(): img = new bg = not bg -iter() -iter() - +for _ in range(2): iter() print(sum(img.values())) - for _ in range(48): iter() - print(sum(img.values())) |