add 2022/day10.1
This commit is contained in:
parent
109ddc67b6
commit
517107044f
1 changed files with 48 additions and 0 deletions
48
2022/10/main.py
Normal file
48
2022/10/main.py
Normal file
|
@ -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()
|
Loading…
Reference in a new issue