1
0
Fork 0
adventofcode/2022/10/main.py
2024-12-12 23:03:58 +01:00

48 lines
1 KiB
Python

#!/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()