day 11
This commit is contained in:
parent
ce02b1c91b
commit
e3c1f47592
|
@ -6,7 +6,7 @@ S = { ")": 3, "]": 57, "}": 1197, ">": 25137, }
|
||||||
L = sys.stdin.read().splitlines()
|
L = sys.stdin.read().splitlines()
|
||||||
N = 0
|
N = 0
|
||||||
for l in L:
|
for l in L:
|
||||||
Q = deque(["y"]*120)
|
Q = deque(["y"]*1)
|
||||||
for c in l:
|
for c in l:
|
||||||
p = Q.pop()
|
p = Q.pop()
|
||||||
if c in D: # if closing char
|
if c in D: # if closing char
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import sys
|
import sys
|
||||||
from collections import deque
|
from collections import deque
|
||||||
D = { ">":"<", ")":"(", "]":"[","}":"{", }
|
D = { ">":"<", ")":"(", "]":"[","}":"{", }
|
||||||
S = { "(":1, "[":2, "{":3, "<":4, }
|
S = { "(":1, "[":2, "{":3, "<":4, }
|
||||||
L = sys.stdin.read().splitlines()
|
L = sys.stdin.read().splitlines()
|
||||||
N = []
|
N = []
|
||||||
for l in L:
|
for l in L:
|
||||||
Q = deque(["y"]*120)
|
Q = deque(["y"]) # add buffer to pop
|
||||||
fail = False
|
fail = False
|
||||||
for c in l:
|
for c in l:
|
||||||
p = Q.pop()
|
p = Q.pop()
|
||||||
|
@ -20,7 +20,7 @@ for l in L:
|
||||||
Q.append(p)
|
Q.append(p)
|
||||||
Q.append(c)
|
Q.append(c)
|
||||||
if not fail:
|
if not fail:
|
||||||
R = list(Q)[120:]
|
R = list(Q)[1:]
|
||||||
s = 0
|
s = 0
|
||||||
for r in reversed(R):
|
for r in reversed(R):
|
||||||
s = s*5 + S[r]
|
s = s*5 + S[r]
|
||||||
|
|
|
@ -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)
|
|
@ -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)
|
|
@ -0,0 +1,10 @@
|
||||||
|
1172728874
|
||||||
|
6751454281
|
||||||
|
2612343533
|
||||||
|
1884877511
|
||||||
|
7574346247
|
||||||
|
2117413745
|
||||||
|
7766736517
|
||||||
|
4331783444
|
||||||
|
4841215828
|
||||||
|
6857766273
|
|
@ -0,0 +1,10 @@
|
||||||
|
5483143223
|
||||||
|
2745854711
|
||||||
|
5264556173
|
||||||
|
6141336146
|
||||||
|
6357385478
|
||||||
|
4167524645
|
||||||
|
2176841721
|
||||||
|
6882881134
|
||||||
|
4846848554
|
||||||
|
5283751526
|
Loading…
Reference in New Issue