diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-12-11 07:34:30 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-12-11 07:39:06 +0100 |
| commit | 38160d02f3d3f189021a4bf19596f522c3220235 (patch) | |
| tree | 3304467fcbca49da57085dbe2b00b4c429cbc343 /20 | |
| parent | 19d081cfa5522d826b65d92269b69ec40360afec (diff) | |
| download | aoc-38160d02f3d3f189021a4bf19596f522c3220235.tar.gz | |
common read
Diffstat (limited to '20')
| -rw-r--r-- | 20/py/d11.py | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/20/py/d11.py b/20/py/d11.py index 5d5e0c5..048367c 100644 --- a/20/py/d11.py +++ b/20/py/d11.py @@ -3,24 +3,17 @@ import aoc20 import sys -def vis(board, w, h): - s = "" +def read(lines): + board = {} + h = len(lines) + w = len(lines[0]) for y in range(h): for x in range(w): - p = (x, y) - if p in board: - if board[p] == -1: - s += "." - elif board[p] == 0: - s += "L" - elif board[p] == 1: - s += "#" - else: - s += "?" - else: - s += "?" - s += "\n" - return s + if lines[y][x] == "L": + board[(x, y)] = 0 + elif lines[y][x] == ".": + board[(x, y)] = -1 + return board, w, h def amount_neighbours_occ(p, board): @@ -36,16 +29,7 @@ def amount_neighbours_occ(p, board): def pt1(_in): - board = {} - h = len(_in) - w = len(_in[0]) - for y in range(h): - for x in range(w): - if _in[y][x] == "L": - board[(x, y)] = 0 - elif _in[y][x] == ".": - board[(x, y)] = -1 - + board, w, h = read(_in) while True: prev_board = board.copy() for p, state in prev_board.items(): @@ -86,16 +70,7 @@ def amount_in_sight_occ(p, board, w, h): def pt2(_in): - board = {} - h = len(_in) - w = len(_in[0]) - for y in range(h): - for x in range(w): - if _in[y][x] == "L": - board[(x, y)] = 0 - elif _in[y][x] == ".": - board[(x, y)] = -1 - + board, w, h = read(_in) while True: prev_board = board.copy() for p, state in prev_board.items(): |
