This commit is contained in:
Sebastian Seedorf
2021-12-13 09:25:50 +01:00
parent e953a32235
commit 8f9365821f
3 changed files with 906 additions and 0 deletions

21
day13/part2.py Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env python3
from functools import reduce
import numpy as np
lines = (x.strip() for x in open("input.txt"))
points = set()
# 1311,895
for line in lines:
if line.startswith("fold along x="):
mark = int(line[13:])
points = set((x if mark > x else 2*mark-x, y) for x, y in points if mark != x)
elif line.startswith("fold along y="):
mark = int(line[13:])
points = set((x, y if mark > y else 2*mark-y) for x, y in points if mark != y)
elif len(line) > 0:
points.add(tuple(int(num) for num in line.split(",")))
max_x, max_y = reduce(lambda p, c: tuple(map(max, zip(p, c))), points)
for line in (''.join('#' if (x, y) in points else ' ' for x in range(max_x+1)) for y in range(max_y+1)):
print(line)