day 24 python minor optimization
i can't believe this is faster but it is (slightly)main
parent
0d46922957
commit
460d51db5c
23
day24/sol.py
23
day24/sol.py
|
@ -8,13 +8,6 @@ import astar
|
|||
|
||||
#print(*data, sep="\n")
|
||||
|
||||
blizzards = {'>': {}, '<': {}, '^': {}, 'v': {}}
|
||||
for y in range(len(data)):
|
||||
for x in range(len(data[y])):
|
||||
c = data[y][x]
|
||||
if c in blizzards:
|
||||
blizzards[c][x,y] = 1
|
||||
|
||||
def show(t):
|
||||
H = len(data)-2
|
||||
for y in range(len(data)):
|
||||
|
@ -27,19 +20,19 @@ def show(t):
|
|||
else:
|
||||
bliz = []
|
||||
u = 1 + ((x - t)-1)%W
|
||||
if (u,y) in blizzards['>']:
|
||||
if data[y][u] == '>':
|
||||
bliz.append('>')
|
||||
|
||||
u = 1 + ((x + t)-1)%W
|
||||
if (u,y) in blizzards['<']:
|
||||
if data[y][u] == '<':
|
||||
bliz.append('<')
|
||||
|
||||
v = 1 + ((y - t)-1)%H
|
||||
if (x,v) in blizzards['v']:
|
||||
if data[v][x] == 'v':
|
||||
bliz.append('v')
|
||||
|
||||
v = 1 + ((y + t)-1)%H
|
||||
if (x,v) in blizzards['^']:
|
||||
if data[v][x] == '^':
|
||||
bliz.append('^')
|
||||
|
||||
if len(bliz) == 0:
|
||||
|
@ -65,19 +58,19 @@ def blocked(x,y,t):
|
|||
W = len(data[y])-2
|
||||
|
||||
u = 1 + ((x - t)-1)%W
|
||||
if (u,y) in blizzards['>']:
|
||||
if data[y][u] == '>':
|
||||
return True
|
||||
|
||||
u = 1 + ((x + t)-1)%W
|
||||
if (u,y) in blizzards['<']:
|
||||
if data[y][u] == '<':
|
||||
return True
|
||||
|
||||
v = 1 + ((y - t)-1)%H
|
||||
if (x,v) in blizzards['v']:
|
||||
if data[v][x] == 'v':
|
||||
return True
|
||||
|
||||
v = 1 + ((y + t)-1)%H
|
||||
if (x,v) in blizzards['^']:
|
||||
if data[v][x] == '^':
|
||||
return True
|
||||
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue