diff --git a/day10/input.txt b/day10/input.txt new file mode 100644 index 0000000..17607bd --- /dev/null +++ b/day10/input.txt @@ -0,0 +1,138 @@ +noop +noop +addx 5 +addx 29 +addx -28 +addx 5 +addx -1 +noop +noop +addx 5 +addx 12 +addx -6 +noop +addx 4 +addx -1 +addx 1 +addx 5 +addx -31 +addx 32 +addx 4 +addx 1 +noop +addx -38 +addx 5 +addx 2 +addx 3 +addx -2 +addx 2 +noop +addx 3 +addx 2 +addx 5 +addx 2 +addx 3 +noop +addx 2 +addx 3 +noop +addx 2 +addx -32 +addx 33 +addx -20 +addx 27 +addx -39 +addx 1 +noop +addx 5 +addx 3 +noop +addx 2 +addx 5 +noop +noop +addx -2 +addx 5 +addx 2 +addx -16 +addx 21 +addx -1 +addx 1 +noop +addx 3 +addx 5 +addx -22 +addx 26 +addx -39 +noop +addx 5 +addx -2 +addx 2 +addx 5 +addx 2 +addx 23 +noop +addx -18 +addx 1 +noop +noop +addx 2 +noop +noop +addx 7 +addx 3 +noop +addx 2 +addx -27 +addx 28 +addx 5 +addx -11 +addx -27 +noop +noop +addx 3 +addx 2 +addx 5 +addx 2 +addx 27 +addx -26 +addx 2 +addx 5 +addx 2 +addx 4 +addx -3 +addx 2 +addx 5 +addx 2 +addx 3 +addx -2 +addx 2 +noop +addx -33 +noop +noop +noop +noop +addx 31 +addx -26 +addx 6 +noop +noop +addx -1 +noop +addx 3 +addx 5 +addx 3 +noop +addx -1 +addx 5 +addx 1 +addx -12 +addx 17 +addx -1 +addx 5 +noop +noop +addx 1 +noop +noop \ No newline at end of file diff --git a/day10/main.py b/day10/main.py new file mode 100644 index 0000000..62ac673 --- /dev/null +++ b/day10/main.py @@ -0,0 +1,37 @@ + +input_file = open("input.txt", "r") +lines = input_file.readlines() + +instructions = [] + +for line in lines: + line = line.strip() + instruction = line.split(" ")[0] + param = None if "noop" == instruction else int(line.split(" ")[-1]) + cycles = 1 if "noop" == instruction else 2 + + instructions.append((instruction, param, cycles)) + +# Part 1 + +register_x = 1 +current_cycle = 1 +signal_strengths = [] +cycle_milestones = [20, 60, 100, 140, 180, 220] + +for instruction in instructions: + for i in range(instruction[2]): + if instruction[0] == "noop": + current_cycle += 1 + + elif instruction[0] == "addx": + current_cycle += 1 + if i == instruction[2] - 1: + register_x += instruction[1] + + if current_cycle in cycle_milestones: + signal_strengths.append(register_x * current_cycle) + + # print("Cycle " + str(current_cycle) + ": " + str(register_x)) + +print("Part 1: " + str(sum(signal_strengths))) diff --git a/day9/main.py b/day9/main.py index 9d3179f..52b3ec8 100644 --- a/day9/main.py +++ b/day9/main.py @@ -1,5 +1,5 @@ import time -from os import system, name +from os import system moves = []