feat: day 10 part 1 complete
This commit is contained in:
138
day10/input.txt
Normal file
138
day10/input.txt
Normal file
@@ -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
|
||||
37
day10/main.py
Normal file
37
day10/main.py
Normal file
@@ -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)))
|
||||
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
from os import system, name
|
||||
from os import system
|
||||
|
||||
moves = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user