42 lines
844 B
Python
42 lines
844 B
Python
|
#!/usr/bin/env python
|
||
|
# 2022 - Advent Of Code 10
|
||
|
|
||
|
|
||
|
# file = 'input_example.txt'
|
||
|
# file = 'input_example2.txt'
|
||
|
file = 'input.txt'
|
||
|
|
||
|
cycle = 1
|
||
|
regX = 1
|
||
|
|
||
|
sumsig = 0
|
||
|
|
||
|
|
||
|
def check_cycle(c, r):
|
||
|
if (c - 20) % 40 == 0:
|
||
|
signal = cycle * r
|
||
|
print(f'cycle {c}: {signal}')
|
||
|
return signal
|
||
|
return 0
|
||
|
|
||
|
|
||
|
with open(file, encoding="utf-8") as f:
|
||
|
for line in f.readlines():
|
||
|
if line.startswith('noop'):
|
||
|
cycle += 1
|
||
|
# print(cycle)
|
||
|
sumsig += check_cycle(cycle, regX)
|
||
|
else:
|
||
|
value = int(line.strip().split(' ')[1])
|
||
|
cycle += 1
|
||
|
# print(cycle)
|
||
|
sumsig += check_cycle(cycle, regX)
|
||
|
|
||
|
cycle += 1
|
||
|
regX += value
|
||
|
sumsig += check_cycle(cycle, regX)
|
||
|
# print(cycle)
|
||
|
# print(cycle)
|
||
|
|
||
|
print(sumsig)
|