#!/usr/bin/env python3 import sys import re coord = re.compile("\d+,\d+") fold = re.compile("fold along") coords = [] folds = [] for l in sys.stdin: l = l.strip() if coord.match(l): coords.append([int(x) for x in l.split(",")]) elif fold.match(l): split = l.split() # x=8 folds.append(split[2].split("=")) prev_folded = {} for d, v in folds: v = int(v) folded = {} for c in coords: x, y = c if d == "x": if x == v: # lost to the fold pass elif x > v: newx = v - (x - v) folded[(newx, y)] = 1 else: folded[(x, y)] = 1 elif d == "y": if y == v: # lost to the fold pass elif y > v: newy = v - (y - v) folded[(x, newy)] = 1 else: folded[(x, y)] = 1 else: raise Exception(f"Bad dir: {d}") coords = folded.keys() prev_folded = folded # Just hope they fit on a terminal! print() for y in range(6): for x in range(120): if (x, y) in prev_folded: print("#", end="") else: print(" ", end="") print()