diff --git a/d10/d10_1.py b/d10/d10_1.py index f140e35..fd4eda5 100644 --- a/d10/d10_1.py +++ b/d10/d10_1.py @@ -6,7 +6,7 @@ S = { ")": 3, "]": 57, "}": 1197, ">": 25137, } L = sys.stdin.read().splitlines() N = 0 for l in L: - Q = deque(["y"]*120) + Q = deque(["y"]*1) for c in l: p = Q.pop() if c in D: # if closing char diff --git a/d10/d10_2.py b/d10/d10_2.py index 36921c3..d17b8d3 100644 --- a/d10/d10_2.py +++ b/d10/d10_2.py @@ -1,11 +1,11 @@ import sys from collections import deque D = { ">":"<", ")":"(", "]":"[","}":"{", } -S = { "(":1, "[":2, "{":3, "<":4, } +S = { "(":1, "[":2, "{":3, "<":4, } L = sys.stdin.read().splitlines() N = [] for l in L: - Q = deque(["y"]*120) + Q = deque(["y"]) # add buffer to pop fail = False for c in l: p = Q.pop() @@ -20,7 +20,7 @@ for l in L: Q.append(p) Q.append(c) if not fail: - R = list(Q)[120:] + R = list(Q)[1:] s = 0 for r in reversed(R): s = s*5 + S[r] diff --git a/d11/d11_1.py b/d11/d11_1.py new file mode 100644 index 0000000..220cada --- /dev/null +++ b/d11/d11_1.py @@ -0,0 +1,29 @@ +import sys +L = list(map(lambda s: [-999]+list(map(int, s))+[-999] ,sys.stdin.read().splitlines())) +L = [[-999]*12] + L + [[-999]*12] +def printgrid(): + for row in L[1:-1]: + print("".join(map(str,row[1:-1]))) +printgrid() +N = 0 +for s in range(100): + D = set() + print("step",s+1) + for x in range(1,11): + for y in range(1,11): + L[x][y] += 1 + flash = True + while flash: + flash = False + for x in range(1,11): + for y in range(1,11): + curr = L[x][y] + if curr > 9: + flash = True + for (i,j) in [(0,1),(1,0),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]: + L[x+i][y+j] += 1 if (x+i,y+j) not in D else 0 + N+=1 + L[x][y] = 0 + D.add((x,y)) # can't increase its energy for the rest of the turn + printgrid() +print(N) diff --git a/d11/d11_2.py b/d11/d11_2.py new file mode 100644 index 0000000..0330474 --- /dev/null +++ b/d11/d11_2.py @@ -0,0 +1,32 @@ +import sys +L = list(map(lambda s: [-999]+list(map(int, s))+[-999] ,sys.stdin.read().splitlines())) +L = [[-999]*12] + L + [[-999]*12] +def printgrid(): + for row in L[1:-1]: + print("".join(map(str,row[1:-1]))) +printgrid() +N = [] +for s in range(1000): + D = set() + print("step",s+1) + for x in range(1,11): + for y in range(1,11): + L[x][y] += 1 + flash = True + while flash: + flash = False + for x in range(1,11): + for y in range(1,11): + curr = L[x][y] + if curr > 9: + flash = True + for (i,j) in [(0,1),(1,0),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]: + L[x+i][y+j] += 1 if (x+i,y+j) not in D else 0 + #N+=1 + L[x][y] = 0 + D.add((x,y)) # can't increase its energy for the rest of the turn + if len(D) == 100: + print(s) + N.append(s) + printgrid() +print(N[0]+1) diff --git a/d11/input b/d11/input new file mode 100644 index 0000000..2163723 --- /dev/null +++ b/d11/input @@ -0,0 +1,10 @@ +1172728874 +6751454281 +2612343533 +1884877511 +7574346247 +2117413745 +7766736517 +4331783444 +4841215828 +6857766273 diff --git a/d11/sample b/d11/sample new file mode 100644 index 0000000..a3819c9 --- /dev/null +++ b/d11/sample @@ -0,0 +1,10 @@ +5483143223 +2745854711 +5264556173 +6141336146 +6357385478 +4167524645 +2176841721 +6882881134 +4846848554 +5283751526 \ No newline at end of file