2022 - Day 10 part 1
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kleph 2023-01-24 22:41:34 +01:00
parent 101f8618c9
commit 0fa4605d49
4 changed files with 329 additions and 0 deletions

41
2022/10/10.py Normal file
View file

@ -0,0 +1,41 @@
#!/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)

139
2022/10/input.txt Normal file
View file

@ -0,0 +1,139 @@
addx 1
noop
noop
noop
addx 5
addx 5
noop
noop
addx 9
addx -5
addx 1
addx 4
noop
noop
noop
addx 6
addx -1
noop
addx 5
addx -2
addx 7
noop
addx 3
addx -2
addx -38
noop
noop
addx 32
addx -22
noop
addx 2
addx 3
noop
addx 2
addx -2
addx 7
addx -2
noop
addx 3
addx 2
addx 5
addx 2
addx -5
addx 10
noop
addx 3
noop
addx -38
addx 1
addx 27
noop
addx -20
noop
addx 2
addx 27
noop
addx -22
noop
noop
noop
noop
addx 3
addx 5
addx 2
addx -11
addx 16
addx -2
addx -17
addx 24
noop
noop
addx 1
addx -38
addx 15
addx 10
addx -15
noop
addx 2
addx 26
noop
addx -21
addx 19
addx -33
addx 19
noop
addx -6
addx 9
addx 3
addx 4
addx -21
addx 4
addx 20
noop
addx 3
addx -38
addx 28
addx -21
addx 9
addx -8
addx 2
addx 5
addx 2
addx -9
addx 14
addx -2
addx -5
addx 12
addx 3
addx -2
addx 2
addx 7
noop
noop
addx -27
addx 28
addx -36
noop
addx 1
addx 5
addx -1
noop
addx 6
addx -1
addx 5
addx 5
noop
noop
addx -2
addx 20
addx -10
addx -3
addx 1
addx 3
addx 2
addx 4
addx 3
noop
addx -30
noop

View file

@ -0,0 +1,3 @@
noop
addx 3
addx -5

146
2022/10/input_example2.txt Normal file
View file

@ -0,0 +1,146 @@
addx 15
addx -11
addx 6
addx -3
addx 5
addx -1
addx -8
addx 13
addx 4
noop
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx -35
addx 1
addx 24
addx -19
addx 1
addx 16
addx -11
noop
noop
addx 21
addx -15
noop
noop
addx -3
addx 9
addx 1
addx -3
addx 8
addx 1
addx 5
noop
noop
noop
noop
noop
addx -36
noop
addx 1
addx 7
noop
noop
noop
addx 2
addx 6
noop
noop
noop
noop
noop
addx 1
noop
noop
addx 7
addx 1
noop
addx -13
addx 13
addx 7
noop
addx 1
addx -33
noop
noop
noop
addx 2
noop
noop
noop
addx 8
noop
addx -1
addx 2
addx 1
noop
addx 17
addx -9
addx 1
addx 1
addx -3
addx 11
noop
noop
addx 1
noop
addx 1
noop
noop
addx -13
addx -19
addx 1
addx 3
addx 26
addx -30
addx 12
addx -1
addx 3
addx 1
noop
noop
noop
addx -9
addx 18
addx 1
addx 2
noop
noop
addx 9
noop
noop
noop
addx -1
addx 2
addx -37
addx 1
addx 3
noop
addx 15
addx -21
addx 22
addx -6
addx 1
noop
addx 2
addx 1
noop
addx -10
noop
noop
addx 20
addx 1
addx 2
addx 2
addx -6
addx -11
noop
noop
noop