From 032f0c4caa561268ed5aeddf8ecef87576bb7828 Mon Sep 17 00:00:00 2001 From: setop Date: Fri, 15 Dec 2023 23:58:40 +0100 Subject: [PATCH] day 14, 1E9 is not more than 1E3 --- d14/part1.py | 30 ++++++++++++++++++++++++++ d14/part2.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 d14/part1.py create mode 100644 d14/part2.py diff --git a/d14/part1.py b/d14/part1.py new file mode 100644 index 0000000..91b81a2 --- /dev/null +++ b/d14/part1.py @@ -0,0 +1,30 @@ +import sys + +# load ptf flat +G = [list(l) for l in sys.stdin.read().splitlines()] +W = len(G[0]) +H = len(G) +print(W,H) + +# move far north each com +for x in range(W): + for y in range(H): + print(f'{x=},{y=} = {G[y][x]}') + if G[y][x] == "O": + for j in range(y-1,0-1,-1): + print(f'{j=}') + if G[j][x] == '.': # can go north + print(f'north, {j=}') + G[j][x] = "O" + G[j+1][x] = "." + else: + break + +S = 0 +for y,row in enumerate(G): + print(''.join(row)) + S += (H-y)*row.count('O') +print(S) + +# compute + diff --git a/d14/part2.py b/d14/part2.py new file mode 100644 index 0000000..e14efad --- /dev/null +++ b/d14/part2.py @@ -0,0 +1,59 @@ +import sys + +I = sys.stdin.read().splitlines() +G = [list(l) for l in I] +W = len(G[0]) +H = len(G) + +def north(): + for x in range(W): + for y in range(H): + if G[y][x] == "O": + for j in range(y-1,0-1,-1): + if G[j][x] == '.': + G[j][x] = "O" + G[j+1][x] = "." + else: + break + +def south(): + for x in range(W): + for y in range(H-1,0-1,-1): + if G[y][x] == "O": + for j in range(y+1,W,1): + if G[j][x] == '.': + G[j][x] = "O" + G[j-1][x] = "." + else: + break + +def east(): + for y in range(H): + for x in range(W-1,0-1,-1): + if G[y][x] == "O": + for i in range(x+1,H,1): + if G[y][i] == '.': + G[y][i] = "O" + G[y][i-1] = "." + else: + break + + +def west(): + for y in range(H): + for x in range(W): + if G[y][x] == "O": + for i in range(x-1,0-1,-1): + if G[y][i] == '.': + G[y][i] = "O" + G[y][i+1] = "." + else: + break + +for _ in range(1_000): + north() + west() + south() + east() + +print(sum((H-y)*row.count('O') for y,row in enumerate(G)))