Skip to content

Commit

Permalink
speedup 2023/23
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Jan 7, 2025
1 parent 0e94181 commit 68b0864
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions aoc_wim/aoc2023/q23.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@


grid = ZGrid(data)
start = 1
end = grid.bottom_right - 1

nodes = {}
dzs = dict(zip("^>v<", [-1j, 1, 1j, -1]))
for z in grid.z(".", first=False):
Expand All @@ -26,8 +23,11 @@ def find_next_node(z0, dz0):
return path[-1], path[-2] - path[-1], len(path) - 1


nodes[start] = {1j: find_next_node(start, 1j)}
nodes[end] = {-1j: find_next_node(end, -1j)}
start, dzS, dS = find_next_node(1, 1j)
grid[start + dzS] = "#"
end, dzE, dE = find_next_node(grid.bottom_right - 1, -1j)
grid[end + dzE] = "#"

for z0, branches in nodes.items():
for dz0 in dzs.values():
g = grid.get(z0 + dz0)
Expand All @@ -39,9 +39,7 @@ def find_next_node(z0, dz0):
node_mask = {z: 1 << i for i, z in enumerate(nodes)}



def longest_path(part="a"):
grid[start + 1j] = "v"
dists = []
stack = [(start, node_mask[start], 0)]
while stack:
Expand All @@ -58,7 +56,7 @@ def longest_path(part="a"):
if part == "a" or {z0, z1} <= perimeter:
continue
stack.append((z1, visited | node_mask[z1], d0 + dist))
return max(dists)
return dS + max(dists) + dE


print("answer_a:", longest_path(part="a"))
Expand Down
1 change: 1 addition & 0 deletions aoc_wim/aoc2023/q24.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def intersect2d(h0, h1):
print("answer_a:", a)


# https://www.reddit.com/r/adventofcode/comments/18pnycy/comment/kepu26z/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button ?
x, y, z, dx, dy, dz = z3.Ints("x y z dx dy dz")
ts = z3.Ints("t0 t1 t2")
s = z3.Solver()
Expand Down

0 comments on commit 68b0864

Please sign in to comment.