This commit is contained in:
2022-12-11 17:37:17 +03:00
parent 9f3ab834b8
commit 43f504ac06
2 changed files with 171 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
with open('input') as file:
cmds = file.read().strip().split('\n')
def execute(cmds):
x = 1
for cmd in cmds:
if cmd=='noop':
yield x
elif cmd.startswith('addx '):
_, v = cmd.split()
v = int(v)
yield x
yield x
x += v
def f(x):
return ((res, i) for res, i in zip(execute(cmds), range(1, x+1)) if i in range(20, 260, 40))
print(sum(res*i for res, i in f(220)))
x = iter(execute(cmds))
for i in range(6):
for j in range(40):
r = next(x)
if r-1<=j<=r+1:
c = "#"
else:
c = '.'
print(c, end='')
print()