41 lines
853 B
Python
Executable file
41 lines
853 B
Python
Executable file
#!/bin/python3
|
|
|
|
program = list()
|
|
|
|
with open('day10.txt', 'r') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line == "noop":
|
|
program.append("noop")
|
|
else:
|
|
[cmd, arg] = line.split(" ")
|
|
program.append((cmd, int(arg)))
|
|
|
|
states = list()
|
|
|
|
state = 1
|
|
for instruction in program:
|
|
if instruction == 'noop':
|
|
states.append(state)
|
|
else:
|
|
(cmd, arg) = instruction
|
|
states.append(state)
|
|
states.append(state)
|
|
state += arg
|
|
|
|
part1 = 0
|
|
|
|
for i in range(19, len(states), 40):
|
|
part1 += (i+1) * states[i]
|
|
|
|
print(part1)
|
|
|
|
for y in range(6):
|
|
for x in range(40):
|
|
index = y * 40 + x
|
|
state = states[index]
|
|
if x == state or x == state-1 or x == state+1:
|
|
print('#', end='')
|
|
else:
|
|
print('.', end='')
|
|
print('')
|