diff --git a/2022-python/output/day_10.py b/2022-python/output/day_10.py new file mode 100644 index 0000000..5ab6fce --- /dev/null +++ b/2022-python/output/day_10.py @@ -0,0 +1,49 @@ +from output import sints + + +def solve(data): + x = 1 + P = data.splitlines() + p1 = 0 + c = 0 + p = 0 + running = True + busy = False + pixels = [] + while running: + if not p < len(P) and not busy: + running = False + continue + line = P[min([p, len(P) - 1])] + if (c + 21) % 40 == 0: + p1 += (c + 1) * x + if c % 40 == 0: + pixels.append("\n") + pixels.append("■" if (x - 1) <= (c % 40) <= (x + 1) else " ") + if busy: + busy = False + x += int(sints(line)[0]) + p += 1 + c += 1 + continue + if line.startswith("noop"): + p += 1 + c += 1 + continue + busy = True + c += 1 + p2 = "".join(pixels) + return p1, p2 + + +if __name__ == "__main__": + with open("./input/10.txt", "r") as f: + inp = f.read().strip() + + p1, p2 = solve(inp) + + print(p1) + print(p2) + + assert p1 == 11820 + # assert p2 == "EPJBRKAH"