Day 13 (glamorized)
This commit is contained in:
@@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
points = set()
|
points = set()
|
||||||
# 1311,895
|
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("fold along x="):
|
if line.startswith("fold along x="):
|
||||||
mark = int(line[13:])
|
fold = int(line[13:])
|
||||||
points = set((x if mark > x else 2*mark-x, y) for x, y in points if mark != x)
|
points = set((fold - abs(x-fold), y) for x, y in points if fold != x)
|
||||||
break
|
break
|
||||||
elif line.startswith("fold along y="):
|
elif line.startswith("fold along y="):
|
||||||
mark = int(line[13:])
|
fold = int(line[13:])
|
||||||
points = set((x, y if mark > y else 2*mark-y) for x, y in points if mark != y)
|
points = set((x, fold - abs(y-fold)) for x, y in points if fold != y)
|
||||||
break
|
break
|
||||||
elif len(line) > 0:
|
elif len(line) > 0:
|
||||||
points.add(tuple(int(num) for num in line.split(",")))
|
points.add(tuple(int(num) for num in line.split(",")))
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from functools import reduce
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
points = set()
|
points = set()
|
||||||
# 1311,895
|
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("fold along x="):
|
if line.startswith("fold along x="):
|
||||||
mark = int(line[13:])
|
fold = int(line[13:])
|
||||||
points = set((x if mark > x else 2*mark-x, y) for x, y in points if mark != x)
|
points = set((fold - abs(x-fold), y) for x, y in points if fold != x)
|
||||||
elif line.startswith("fold along y="):
|
elif line.startswith("fold along y="):
|
||||||
mark = int(line[13:])
|
fold = int(line[13:])
|
||||||
points = set((x, y if mark > y else 2*mark-y) for x, y in points if mark != y)
|
points = set((x, fold - abs(y-fold)) for x, y in points if fold != y)
|
||||||
elif len(line) > 0:
|
elif len(line) > 0:
|
||||||
points.add(tuple(int(num) for num in line.split(",")))
|
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)
|
max_x, max_y = tuple(map(max, zip(*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)):
|
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)
|
print(line)
|
||||||
|
|||||||
Reference in New Issue
Block a user