advent_of_code/2022/10/10.py
kleph 0fa4605d49
All checks were successful
continuous-integration/drone/push Build is passing
2022 - Day 10 part 1
2023-01-24 22:41:34 +01:00

41 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)