From 2c00b3224156b5813873172706ac82aeb562f402 Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 10 Dec 2022 13:23:13 +0100 Subject: [PATCH] day 10, easy peasy --- d10/part1.py | 23 +++++++++++++++++++++++ d10/part2.py | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 d10/part1.py create mode 100644 d10/part2.py diff --git a/d10/part1.py b/d10/part1.py new file mode 100644 index 0000000..ff9935e --- /dev/null +++ b/d10/part1.py @@ -0,0 +1,23 @@ +import sys + +X = 1 +C = 0 +S = [] +I = {20, 60, 100, 140, 180, 220} + +def inc(): + global C + C += 1 + if C in I: + S.append(C*X) + +for l in sys.stdin.read().splitlines(): + m, q = (l+" _").split(" ")[:2] + if m == "noop": + inc() + else: # add + inc() + inc() + X += int(q) + +print(sum(S)) diff --git a/d10/part2.py b/d10/part2.py new file mode 100644 index 0000000..fe6f499 --- /dev/null +++ b/d10/part2.py @@ -0,0 +1,23 @@ +import sys + +X = 1 +C = 0 +LCD = [["."]*40 for _ in range(6)] + +def inc(): + global C + (r,c) = divmod(C, 40) + C+=1 + if c in [X, X-1, X+1]: + LCD[r][c]="#" + +for l in sys.stdin.read().splitlines(): + m, q = (l+" _").split(" ")[:2] + if m == "noop": + inc() + else: # add + inc() + inc() + X += int(q) + +print("\n".join("".join(r) for r in LCD))