diff --git a/2022/10/10.py b/2022/10/10.py new file mode 100644 index 0000000..86b1f9b --- /dev/null +++ b/2022/10/10.py @@ -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) diff --git a/2022/10/input.txt b/2022/10/input.txt new file mode 100644 index 0000000..e34c882 --- /dev/null +++ b/2022/10/input.txt @@ -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 diff --git a/2022/10/input_example.txt b/2022/10/input_example.txt new file mode 100644 index 0000000..f428b7b --- /dev/null +++ b/2022/10/input_example.txt @@ -0,0 +1,3 @@ +noop +addx 3 +addx -5 diff --git a/2022/10/input_example2.txt b/2022/10/input_example2.txt new file mode 100644 index 0000000..37ee8ee --- /dev/null +++ b/2022/10/input_example2.txt @@ -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