Skip to content

Commit e6d9a4e

Browse files
committed
Add day 18
1 parent 22473db commit e6d9a4e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

2024/18/18.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import networkx as nx
2+
from bisect import bisect
23

34
def solve(obstacles, S=70):
45
G = nx.grid_graph((S+1, S+1))
@@ -9,10 +10,5 @@ def solve(obstacles, S=70):
910
obstacles = [tuple(map(int, line.split(","))) for line in open(0)]
1011
print(solve(obstacles[:1024])-1)
1112

12-
lo, hi = 1024, len(obstacles)-1
13-
while lo < hi:
14-
mid = (lo + hi) // 2
15-
if solve(obstacles[:mid]): lo = mid+1
16-
else: hi = mid-1
17-
18-
print(*obstacles[mid], sep=",")
13+
index = bisect(range(len(obstacles)), 0, key=lambda x: not solve(obstacles[:x]))
14+
print(*obstacles[index-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