X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=13_1.py;fp=13_1.py;h=678c3cd7272ef111a661126f5d91e066225d53f1;hb=51c5bd4e54ddb0a8a41255b58ff8ffa620db0b99;hp=0000000000000000000000000000000000000000;hpb=4454840b6a5043de026507b46ff087a3ae5b1417;p=max%2Fadvent_of_code_2021.git diff --git a/13_1.py b/13_1.py new file mode 100644 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))