Skip to content

Commit 378adbe

Browse files
committed
Add day 18
1 parent e6d9a4e commit 378adbe

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

2024/18/18.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import networkx as nx
22
from bisect import bisect
33

4-
def solve(obstacles, S=70):
4+
def solve(bad, S=70):
55
G = nx.grid_graph((S+1, S+1))
6-
G.remove_nodes_from(obstacles)
6+
G.remove_nodes_from(bad)
77
return nx.has_path(G, (0,0), (S,S)) \
8-
and len(nx.shortest_path(G, (0,0), (S,S)))
8+
and nx.shortest_path_length(G, (0,0), (S,S))
99

10-
obstacles = [tuple(map(int, line.split(","))) for line in open(0)]
11-
print(solve(obstacles[:1024])-1)
10+
bad = [tuple(map(int, line.split(","))) for line in open(0)]
11+
print(solve(bad[:1024]))
1212

13-
index = bisect(range(len(obstacles)), 0, key=lambda x: not solve(obstacles[:x]))
14-
print(*obstacles[index-1], sep=",")
13+
i = bisect(range(len(bad)), 0, key=lambda x: not solve(bad[:x]))
14+
print(*bad[i-1], sep=",")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy