Improve lib and use it to solve 3 and 17.

This commit is contained in:
2023-12-17 23:57:55 -05:00
parent 1b3e58c307
commit 5626205b2f
3 changed files with 78 additions and 41 deletions

13
d17.py
View File

@@ -28,7 +28,7 @@ def solve(i: Input, second=False):
pos, dirs = node
repeats, prev_dir = dirs
nbs = []
for dir in [NORTH, WEST, SOUTH, EAST]:
for dir in g.dirs_ort():
if second:
if repeats < 4 and prev_dir is not None and prev_dir != dir:
continue
@@ -37,18 +37,11 @@ def solve(i: Input, second=False):
else:
if repeats == 3 and prev_dir == dir:
continue
if prev_dir == NORTH and dir == SOUTH:
continue
elif prev_dir == SOUTH and dir == NORTH:
continue
elif prev_dir == EAST and dir == WEST:
continue
elif prev_dir == WEST and dir == EAST:
if prev_dir == g.flip_ort(dir):
continue
nb = add2(pos, dir)
if not g.contains(nb):
if nb not in g:
continue
nbs.append((nb, (repeats + 1 if dir == prev_dir else 1, dir)))
return nbs