From 8ce27f3bb40f9bc520fdeed5bd8272e909df67bb Mon Sep 17 00:00:00 2001 From: mid-kid Date: Fri, 11 Dec 2020 15:49:56 +0100 Subject: [PATCH] Add day 11 I guess the code could be worse... --- d11.py | 46 +++++++++++++++++++++++++ d11_input.txt | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ d11_output.txt | 2 ++ 3 files changed, 141 insertions(+) create mode 100755 d11.py create mode 100644 d11_input.txt create mode 100644 d11_output.txt diff --git a/d11.py b/d11.py new file mode 100755 index 0000000..402aab9 --- /dev/null +++ b/d11.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +from sys import argv + +i = [list(x.strip()) for x in open(argv[1])] +w = len(i[0]) +h = len(i) + +d = ( + (-1,-1), (-1, 0), (-1,+1), + ( 0,-1), ( 0,+1), + (+1,-1), (+1, 0), (+1,+1) +) + +def f(p2): + o = i + while True: + n = [[None]*w for x in range(h)] + for y, iy in enumerate(o): + for x, c in enumerate(iy): + a = 0 + for v in d: + cy = y+v[0] + cx = x+v[1] + while cy >= 0 and cx >= 0 and cy < h and cx < w: + cc = o[cy][cx] + if cc == "#": + a += 1 + break + if cc == "L" or not p2: + break + cy += v[0] + cx += v[1] + if c == "L" and a == 0: + n[y][x] = "#" + continue + if c == "#" and a >= (4 if not p2 else 5): + n[y][x] = "L" + continue + n[y][x] = c + if str(n) == str(o): + return n + o = n + +print(sum(x.count("#") for x in f(False))) +print(sum(x.count("#") for x in f(True))) diff --git a/d11_input.txt b/d11_input.txt new file mode 100644 index 0000000..60459f2 --- /dev/null +++ b/d11_input.txt @@ -0,0 +1,93 @@ +LLLLLLLLL.L.LLLL.LLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLL.LLLL..LLLLLL.LLLLLLLL.LLLLL.LL.LLLLLLLLLL +LLLLLLLLL.LLLLLLLLLL..LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLL.LLLLLL.LLLLLLLLLLLLLLL..LL.LLLLLLLLLLLLLLLL +L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LLLL.L.LLL.LLLLLL.LLL.LLLL.L.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLL +LLLLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LL.LLL.LLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLL +LLLLLLLLL.LLLLLLLLLLLLL.LLLLLL.LL.LLLLL.LLLLLLLLLLLLLLLL.LLLL.LLLLLLL.LLLLLLL.LLLLLLLLL.LLLLLLLLLL +L.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLL.LLLL.LLLLLL..LLLLLLL.LLLLLLLLL.LLLLLLLLLL diff --git a/d11_output.txt b/d11_output.txt new file mode 100644 index 0000000..0e96394 --- /dev/null +++ b/d11_output.txt @@ -0,0 +1,2 @@ +2329 +2138