]> git.friedersdorff.com Git - max/advent_of_code_2021.git/blobdiff - 13_1.py
Finish day 12 and 13
[max/advent_of_code_2021.git] / 13_1.py
diff --git a/13_1.py b/13_1.py
new file mode 100644 (file)
index 0000000..678c3cd
--- /dev/null
+++ b/13_1.py
@@ -0,0 +1,43 @@
+""" Count the dots on slightly folded transparent paper """
+
+dots = set()
+with open("13_input.txt") as f:
+    for line in f:
+        if line.strip() == "":
+            break
+        else:
+            dots.add(tuple(int(a) for a in line.split(",")))
+
+    for fold in f:
+        direction, fold_line = fold.strip().split(" ")[2].split("=")
+        fold_line = int(fold_line)
+
+        folded_dots = set()
+        for x, y in dots:
+            if direction == "x" and x > fold_line:
+                diff = x - fold_line
+                x = fold_line - diff
+            elif direction == "y" and y > fold_line:
+                diff = y - fold_line
+                y = fold_line - diff
+
+            folded_dots.add((x, y))
+
+        dots = folded_dots
+        # break  # First part just wants the number of dots after first fold.
+
+
+
+xs, ys = list(zip(*dots))
+max_x = max(xs)
+max_y = max(ys)
+
+for j in range(max_y + 1):
+    line = []
+    for i in range(max_x + 1):
+        if (i, j) in dots:
+            line.append("#")
+        else:
+            line.append(".")
+
+    print("".join(line))