This commit is contained in:
Anders Englöf Ytterström 2025-12-09 19:34:15 +01:00
parent cea6397499
commit 335db26ad4
2 changed files with 32 additions and 34 deletions

View file

@ -118,8 +118,8 @@ def svg(seen):
l = min(l, x)
H = b - t + 1
W = r - l + 1
print(t, r, b, l)
im = Image.new(mode="RGB", size=(W,H), color=(255,255,255))
print(H, "*", W)
for y, x in seen:
im.putpixel((x-l, y-t), (0, 0, 0, 255))
im.save("aoc.png")

View file

@ -33,44 +33,42 @@ def solve(data):
break
S = E
# find out a better start for Flood fill by visualizing
Y = 1841
X = 53478
Y = 50000
X = 25000
# or, find a way to floodfill without BFS
# end
y, x = Y, X
Q = [(y, x)]
V = V | B
print(len(B))
svg(B)
# while Q:
# yx = Q.pop()
# if yx in V:
# continue
# V.add(yx)
# y, x = yx
# for dy, dx in D:
# Q.append((dy + y, dx + x))
# for a, b in combinations(A, r=2):
# y1, x1 = a
# y2, x2 = b
# x = abs(x1 - x2) + 1
# y = abs(y1 - y2) + 1
# p1 = max(p1, x * y)
# if (
# len(
# set(
# [
# (min(y1, y2), min(x1, x2)),
# (min(y1, y2), max(x1, x2)),
# (max(y1, y2), min(x1, x2)),
# (max(y1, y2), max(x1, x2)),
# ]
# )
# - V
# )
# == 0
# ):
# p2 = max(p2, max(p2, x * y))
while Q:
yx = Q.pop()
if yx in V:
continue
V.add(yx)
y, x = yx
for dy, dx in D:
Q.append((dy + y, dx + x))
for a, b in combinations(A, r=2):
y1, x1 = a
y2, x2 = b
x = abs(x1 - x2) + 1
y = abs(y1 - y2) + 1
p1 = max(p1, x * y)
if (
len(
set(
[
(min(y1, y2), min(x1, x2)),
(min(y1, y2), max(x1, x2)),
(max(y1, y2), min(x1, x2)),
(max(y1, y2), max(x1, x2)),
]
)
- V
)
== 0
):
p2 = max(p2, max(p2, x * y))
return p1, p2