day 10 part 2

This commit is contained in:
2022-12-10 09:07:25 +02:00
parent eadc405a0f
commit 5849a1bab2
2 changed files with 393 additions and 4 deletions

36
10/j.py
View File

@@ -8,23 +8,51 @@ cost = {
'addx': 2
}
H = 6
W = 40
screen = []
for y in range(H):
tmp = ''
for x in range(W):
tmp += '.'
screen.append(tmp)
cycle = 1
l = 0
finish = len(input)
X = 1
strs = []
line = 1
for l in input:
cmd = l.split()
for i in range(cost[cmd[0]]):
#print(cycle, X, strs)
pos = cycle % 40 - 1
# p1
if ((cycle+20) % 40) == 0:
strenth = cycle*X
# print(">> " + str(cycle) + " " + str(strenth))
strs.append(strenth)
# p2
if cycle % 40 == 0:
line += 1
if (pos == X-1 or pos == X or pos == X+1):
cur = screen[line-1]
screen[line-1] = cur[:pos] + "#" + cur[pos+1:]
cycle += 1
if cmd[0] == 'addx':
X += int(cmd[1])
# p1
print(sum(strs))
# p2
for y in range(H):
tmp = ''
for x in range(W):
tmp += screen[y][x]
print(tmp)