From 0f709f9f03cad90c0a2328ecb10eaa0a42dea068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Fri, 28 Nov 2025 00:24:56 +0100 Subject: [PATCH] Solve 2022 dat 10 pt 1-2 Not pretty, but it works :) --- 2022-python/output/day_10.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 2022-python/output/day_10.py 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"