Skip to content

Commit 4c120a6

Browse files
committed
Add day 20
1 parent 88026c2 commit 4c120a6

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

2024/20/20.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import networkx as nx
2+
from collections import *
3+
4+
25
coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip().replace(".", " "))}
36

47
d4 = [1, 1j, -1, -1j]
@@ -12,21 +15,45 @@
1215

1316
S = [c for c in coords if coords[c] in 'S'][0]
1417
E = [c for c in coords if coords[c] in 'E'][0]
15-
EL = nx.shortest_path_length(G, target=E)
18+
# EL = nx.shortest_path_length(G, target=E)
1619
SL = nx.shortest_path_length(G, source=S)
1720
print(SL)
18-
print(EL)
19-
# exit()
20-
L = {l: max(EL[l], SL[l]) for l in EL}
21+
# print(EL)
22+
C= Counter()
23+
24+
sl = list(SL.items())
25+
seen = set()
26+
s2 = 0
27+
for i, (c1, dist1) in enumerate(sl):
28+
for c2, dist2 in sl[i+1:]:
29+
diff = c2-c1
30+
diff = int(abs(diff.real) + abs(diff.imag))
31+
if diff <= 20:
32+
D = dist2 - dist1 - diff
33+
if D > 0:
34+
C[D] += 1
35+
if D >= 100:
36+
s2 += 1
37+
38+
for asd in sorted(C.items()):
39+
print(asd)
40+
41+
print(s2)
42+
exit()
43+
# L = {l: max(EL[l], SL[l]) for l in EL}
44+
45+
for c in coords:
46+
for d in [1, 1j, -1, -1j]:
47+
if coords[c] != '#' != coords[c+d]:
48+
G.add_edge(c, c+d)
49+
G.add_edge((c, 1), (c+d, 1))
2150

2251
# L = [el+sl for ]
2352

2453
# print(L)
2554
# print(L[S])
2655
# exit(0)
2756

28-
from collections import *
29-
3057
C = Counter()
3158

3259
s1 = 0

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