From 517107044f8d3dfc8bbcbb8f8f5eb0b39bc3ddaa Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 12 Dec 2024 23:03:58 +0100 Subject: [PATCH] add 2022/day10.1 --- 2022/10/main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 2022/10/main.py diff --git a/2022/10/main.py b/2022/10/main.py new file mode 100644 index 0000000..4927441 --- /dev/null +++ b/2022/10/main.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- encoding: utf-8; py-indent-offset: 4 -*- + +# Author: Sebastian Mark +# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de) + +# pylint: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string + + +def readinput(): + with open("input", "r", encoding="utf-8") as file: + lines = [line.rstrip("\n") for line in file] + return lines + + +def get_registers(operations: list) -> list: + registers = {} + x = 1 + + cycle = 1 + for operation in operations: + + cycle += 1 + + if operation != "noop": + _, num = operation.split() + registers[cycle] = x + cycle += 1 + x += int(num) + + registers[cycle] = x + + return registers + + +def main(): + operations = readinput() + + # part 1 + registers = get_registers(operations) + singal_strength = sum( + registers[cycle] * cycle for cycle in [20, 60, 100, 140, 180, 220] + ) + print("Signal strength: %d" % singal_strength) + + +if __name__ == "__main__": + main()