From 89adfb151a19501e76253308864d526f3d5325d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 10 Dec 2022 10:24:23 +0100 Subject: [PATCH] Add day 10. --- 2022/day10.py | 40 ++++++++++++ 2022/inputs/day10.txt | 144 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 2022/day10.py create mode 100644 2022/inputs/day10.txt diff --git a/2022/day10.py b/2022/day10.py new file mode 100644 index 0000000..5519cf2 --- /dev/null +++ b/2022/day10.py @@ -0,0 +1,40 @@ +# -*- encoding: utf-8 -*- + +import sys + +lines = sys.stdin.read().splitlines() + +cycle = 1 +x = 1 + +values = {cycle: x} + +for line in lines: + cycle += 1 + + if line == "noop": + pass + else: + r = int(line.split()[1]) + + values[cycle] = x + + cycle += 1 + x += r + + values[cycle] = x + +answer_1 = sum(c * values[c] for c in range(20, max(values.keys()) + 1, 40)) +print(f"answer 1 is {answer_1}") + + +for i in range(6): + for j in range(40): + v = values[1 + i * 40 + j] + + if j >= v - 1 and j <= v + 1: + print("#", end="") + else: + print(".", end="") + + print() diff --git a/2022/inputs/day10.txt b/2022/inputs/day10.txt new file mode 100644 index 0000000..4be34cb --- /dev/null +++ b/2022/inputs/day10.txt @@ -0,0 +1,144 @@ +addx 1 +addx 4 +addx 1 +noop +addx 4 +addx 3 +addx -2 +addx 5 +addx -1 +noop +addx 3 +noop +addx 7 +addx -1 +addx 1 +noop +addx 6 +addx -1 +addx 5 +noop +noop +noop +addx -37 +addx 7 +noop +noop +noop +addx 5 +noop +noop +noop +addx 9 +addx -8 +addx 2 +addx 5 +addx 2 +addx 5 +noop +noop +addx -2 +noop +addx 3 +addx 2 +noop +addx 3 +addx 2 +noop +addx 3 +addx -36 +noop +addx 26 +addx -21 +noop +noop +noop +addx 3 +addx 5 +addx 2 +addx -4 +noop +addx 9 +addx 5 +noop +noop +noop +addx -6 +addx 7 +addx 2 +noop +addx 3 +addx 2 +addx 5 +addx -39 +addx 34 +addx 5 +addx -35 +noop +addx 26 +addx -21 +addx 5 +addx 2 +addx 2 +noop +addx 3 +addx 12 +addx -7 +noop +noop +noop +noop +noop +addx 5 +addx 2 +addx 3 +noop +noop +noop +noop +addx -37 +addx 21 +addx -14 +addx 16 +addx -11 +noop +addx -2 +addx 3 +addx 2 +addx 5 +addx 2 +addx -15 +addx 6 +addx 12 +addx -2 +addx 9 +addx -6 +addx 7 +addx 2 +noop +noop +noop +addx -33 +addx 1 +noop +addx 2 +addx 13 +addx 15 +addx -21 +addx 21 +addx -15 +noop +noop +addx 4 +addx 1 +noop +addx 4 +addx 8 +addx 6 +addx -11 +addx 5 +addx 2 +addx -35 +addx -1 +noop +noop