Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 88026c2

Browse filesBrowse files
committed
Add day 20
1 parent e80cb6f commit 88026c2
Copy full SHA for 88026c2

File tree

3 files changed

+84
-2
lines changed
Filter options

3 files changed

+84
-2
lines changed

‎.aoc_tiles/tiles/2024/20.png

Copy file name to clipboard
7.79 KB
Loading

‎2024/20/20.py

Copy file name to clipboard
+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import networkx as nx
2+
coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip().replace(".", " "))}
3+
4+
d4 = [1, 1j, -1, -1j]
5+
6+
G = nx.Graph()
7+
for c in coords:
8+
for d in [1, 1j, -1, -1j]:
9+
if coords[c] != '#' != coords[c+d]:
10+
G.add_edge(c, c+d)
11+
# G.add_edge((c, 1), (c+d, 1))
12+
13+
S = [c for c in coords if coords[c] in 'S'][0]
14+
E = [c for c in coords if coords[c] in 'E'][0]
15+
EL = nx.shortest_path_length(G, target=E)
16+
SL = nx.shortest_path_length(G, source=S)
17+
print(SL)
18+
print(EL)
19+
# exit()
20+
L = {l: max(EL[l], SL[l]) for l in EL}
21+
22+
# L = [el+sl for ]
23+
24+
# print(L)
25+
# print(L[S])
26+
# exit(0)
27+
28+
from collections import *
29+
30+
C = Counter()
31+
32+
s1 = 0
33+
seen= set()
34+
for c in coords:
35+
for d in [1, 1j, -1, -1j]:
36+
for d2 in [d]:
37+
diff = 0
38+
for d3 in [0]:
39+
c2 = c+d+d2+d3
40+
if c2 in coords and coords[c] != '#' != coords[c2] and c != c2:
41+
delta = d+d2+d3
42+
new = SL[c2] - SL[c] - int(abs(delta.imag) + abs(delta.real))
43+
print("\t", d3, new)
44+
diff = max(diff, new)
45+
if (c, c+d+d2) not in seen and diff > 0:
46+
seen.add((c, c+d+d2))
47+
seen.add((c+d+d2, c))
48+
if diff > 0:
49+
# print(c, c2)
50+
C[diff] += 1
51+
if diff >= 30:
52+
print(diff)
53+
for y in range(15):
54+
for x in range(15):
55+
X=x+y*1j
56+
print(end=coords[X] if X not in [c, c+d+d2] else "!")
57+
print(end=f"{SL.get(X, '##'):2}")
58+
print()
59+
print()
60+
if diff >= 100:
61+
s1 += 1
62+
63+
64+
for asd in sorted(C.items()):
65+
print(asd)
66+
67+
# 536
68+
# 677
69+
# 1923
70+
71+
72+
# for path in nx.all_simple_paths(G, S, (E, 1), cutoff=L):
73+
# if L - len(path) >= 100:
74+
# s1 += 1
75+
print(s1)
76+
# paths = list(nx.all_shortest_paths(G, S, (E, 0), "weight"))
77+
78+
# print(sum(G.edges[e]["weight"] for e in zip(paths[0], paths[0][1:])))
79+
# print(len({p[0] for p in sum(paths, [])}))

‎README.md

Copy file name to clipboardExpand all lines: README.md
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- AOC TILES BEGIN -->
22
<h1 align="center">
3-
Advent of Code - 248/488
3+
Advent of Code - 249/490
44
</h1>
55
<h1 align="center">
6-
2024 - 38 ⭐ - Python
6+
2024 - 39 ⭐ - Python
77
</h1>
88
<a href="2024/01/01.py">
99
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
@@ -62,6 +62,9 @@
6262
<a href="2024/19/19.py">
6363
<img src=".aoc_tiles/tiles/2024/19.png" width="161px">
6464
</a>
65+
<a href="2024/20/20.py">
66+
<img src=".aoc_tiles/tiles/2024/20.png" width="161px">
67+
</a>
6568
<h1 align="center">
6669
2023 - 50 ⭐ - Python
6770
</h1>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.