day11: ever so slightly faster - still 2s +/- 0.2
This commit is contained in:
parent
c3cced9c4d
commit
6df1f468d3
17
day11.py
17
day11.py
@ -35,23 +35,22 @@ def simulate(layout, max_x, max_y, wide=False):
|
||||
continue
|
||||
|
||||
occupied_seats = 0
|
||||
for cx in [-1, 0, 1]:
|
||||
for cy in [-1, 0, 1]:
|
||||
if cx == 0 and cy == 0:
|
||||
for cx in [x-1, x, x+1]:
|
||||
for cy in [y-1, y, y+1]:
|
||||
if cx == x and cy == y:
|
||||
continue
|
||||
|
||||
test_x = x + cx
|
||||
test_y = y + cy
|
||||
check_value = layout[(test_x, test_y)]
|
||||
check_value = layout[(cx, cy)]
|
||||
|
||||
if check_value is not None:
|
||||
occupied_seats += check_value
|
||||
elif wide:
|
||||
test_x = cx + (cx - x)
|
||||
test_y = cy + (cy - y)
|
||||
while 0 <= test_x <= max_x and 0 <= test_y <= max_y:
|
||||
test_x += cx
|
||||
test_y += cy
|
||||
if layout[(test_x, test_y)] is None:
|
||||
continue
|
||||
test_x += (cx - x)
|
||||
test_y += (cy - y)
|
||||
else:
|
||||
occupied_seats += layout[(test_x, test_y)]
|
||||
break
|
||||
|
||||
Loading…
Reference in New Issue
Block a user