-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday_13_part_1.py
46 lines (33 loc) · 1.06 KB
/
day_13_part_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
################################
# Day 13 - Transparent Origami #
# Part 1 #
################################
def main():
# Load input
with open("inputs/day_13.txt") as file:
data = file.read().split("\n\n")
# Parse input
points = [
[int(coord) for coord in point.split(",")]
for point in data[0].split("\n")
]
folds = [
[int(char) if char.isdigit() else char for char in fold[11:].split("=")]
for fold in data[1].split("\n")
]
# Complete first fold
fold = folds[0]
if fold[0] == "x": fold_axis = 0
else: fold_axis = 1
affected_points = [point for point in points if point[fold_axis] > fold[1]]
for point in affected_points:
points.remove(point)
mirror_length = point[fold_axis] - fold[1]
point[fold_axis] = fold[1] - mirror_length
if point not in points:
points.append(point)
# Output results
print(f"Visible points: {len(points)}")
# Run script
if __name__ == "__main__":
main()