day 24 python minor optimization

i can't believe this is faster but it is (slightly)
main
magical 2022-12-24 11:22:49 -08:00
parent 0d46922957
commit 460d51db5c
1 changed files with 8 additions and 15 deletions

View File

@ -8,13 +8,6 @@ import astar
#print(*data, sep="\n") #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): def show(t):
H = len(data)-2 H = len(data)-2
for y in range(len(data)): for y in range(len(data)):
@ -27,19 +20,19 @@ def show(t):
else: else:
bliz = [] bliz = []
u = 1 + ((x - t)-1)%W u = 1 + ((x - t)-1)%W
if (u,y) in blizzards['>']: if data[y][u] == '>':
bliz.append('>') bliz.append('>')
u = 1 + ((x + t)-1)%W u = 1 + ((x + t)-1)%W
if (u,y) in blizzards['<']: if data[y][u] == '<':
bliz.append('<') bliz.append('<')
v = 1 + ((y - t)-1)%H v = 1 + ((y - t)-1)%H
if (x,v) in blizzards['v']: if data[v][x] == 'v':
bliz.append('v') bliz.append('v')
v = 1 + ((y + t)-1)%H v = 1 + ((y + t)-1)%H
if (x,v) in blizzards['^']: if data[v][x] == '^':
bliz.append('^') bliz.append('^')
if len(bliz) == 0: if len(bliz) == 0:
@ -65,19 +58,19 @@ def blocked(x,y,t):
W = len(data[y])-2 W = len(data[y])-2
u = 1 + ((x - t)-1)%W u = 1 + ((x - t)-1)%W
if (u,y) in blizzards['>']: if data[y][u] == '>':
return True return True
u = 1 + ((x + t)-1)%W u = 1 + ((x + t)-1)%W
if (u,y) in blizzards['<']: if data[y][u] == '<':
return True return True
v = 1 + ((y - t)-1)%H v = 1 + ((y - t)-1)%H
if (x,v) in blizzards['v']: if data[v][x] == 'v':
return True return True
v = 1 + ((y + t)-1)%H v = 1 + ((y + t)-1)%H
if (x,v) in blizzards['^']: if data[v][x] == '^':
return True return True
return False return False