]> git.friedersdorff.com Git - max/advent_of_code_2021.git/blob - 13_1.py
Try day 14
[max/advent_of_code_2021.git] / 13_1.py
1 """ Count the dots on slightly folded transparent paper """
2
3 dots = set()
4 with open("13_input.txt") as f:
5     for line in f:
6         if line.strip() == "":
7             break
8         else:
9             dots.add(tuple(int(a) for a in line.split(",")))
10
11     for fold in f:
12         direction, fold_line = fold.strip().split(" ")[2].split("=")
13         fold_line = int(fold_line)
14
15         folded_dots = set()
16         for x, y in dots:
17             if direction == "x" and x > fold_line:
18                 diff = x - fold_line
19                 x = fold_line - diff
20             elif direction == "y" and y > fold_line:
21                 diff = y - fold_line
22                 y = fold_line - diff
23
24             folded_dots.add((x, y))
25
26         dots = folded_dots
27         # break  # First part just wants the number of dots after first fold.
28
29
30
31 xs, ys = list(zip(*dots))
32 max_x = max(xs)
33 max_y = max(ys)
34
35 for j in range(max_y + 1):
36     line = []
37     for i in range(max_x + 1):
38         if (i, j) in dots:
39             line.append("#")
40         else:
41             line.append(".")
42
43     print("".join(line))