""" 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))