wip
This commit is contained in:
parent
f971917640
commit
cea6397499
2 changed files with 67 additions and 32 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import re
|
||||
from math import inf
|
||||
from PIL import Image
|
||||
|
||||
# Directions/Adjacents for 2D matrices, in the order UP, RIGHT, DOWN, LEFT
|
||||
D = [
|
||||
|
|
@ -97,8 +98,40 @@ def vdbg(seen, mask=("#", "."), M=None):
|
|||
C, Z = mask
|
||||
def _m(r, c):
|
||||
return M[r][c] if M else Z
|
||||
O = []
|
||||
for r in range(H):
|
||||
print("".join([C if (r + osr, c + osc) in seen else _m(r, c) for c in range(W)]))
|
||||
O.append("".join([C if (r + osr, c + osc) in seen else _m(r, c) for c in range(W)]))
|
||||
print("\n".join(O))
|
||||
|
||||
|
||||
def svg(seen):
|
||||
"""Print-debug visited positions of a matrix"""
|
||||
t = inf
|
||||
l = inf
|
||||
b = 0
|
||||
r = 0
|
||||
rects = []
|
||||
for y, x in seen:
|
||||
t = min(t, y)
|
||||
r = max(r, x)
|
||||
b = max(b, y)
|
||||
l = min(l, x)
|
||||
H = b - t + 1
|
||||
W = r - l + 1
|
||||
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")
|
||||
|
||||
for y, x in seen:
|
||||
rects.append(f"<rect x='{x-l}' y='{y-t}' width='1' fill='black' stroke='black' stroke-width='10' height='1' />")
|
||||
with open("svg.svg", "w") as f:
|
||||
f.write(f"""
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" width="{W}" height="{H}">
|
||||
{"".join(rects)}
|
||||
</svg>
|
||||
""".strip())
|
||||
|
||||
|
||||
def vvdbg(seen, h, w):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from itertools import combinations
|
||||
import PIL
|
||||
|
||||
from output import ints
|
||||
from output import svg, D, ints, vdbg
|
||||
|
||||
|
||||
def solve(data):
|
||||
|
|
@ -11,7 +12,6 @@ def solve(data):
|
|||
S = A[0]
|
||||
V = set()
|
||||
B = set()
|
||||
|
||||
while True:
|
||||
V.add(S)
|
||||
y, x = S
|
||||
|
|
@ -40,35 +40,37 @@ def solve(data):
|
|||
y, x = Y, X
|
||||
Q = [(y, x)]
|
||||
V = V | 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))
|
||||
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))
|
||||
return p1, p2
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue