day 10 part 2
This commit is contained in:
36
10/j.py
36
10/j.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user