Add solution for day 10
This commit is contained in:
1 parent
2e96f47274
commit
8086e4b37c
5 files changed
+655
No files matched your search
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
def show_crt(crt):
|
||||
pixels = ''
|
||||
for x in range(240):
|
||||
p = '#' if crt[x] == 1 else '.'
|
||||
pixels = pixels + p
|
||||
if (x % 40) == 39:
|
||||
print(pixels)
|
||||
pixels = ''
|
||||
|
||||
if __name__ == '__main__':
|
||||
ops = [tuple(line.strip('\n').split(' ')) for line in open(sys.argv[1])]
|
||||
reg = 1
|
||||
cycle = 1
|
||||
strength = 0
|
||||
crt = [0] * 240
|
||||
|
||||
for op in ops:
|
||||
if (cycle % 40) == 20: strength = strength + reg * cycle
|
||||
if (cycle % 40) in [reg,reg+1,reg+2]: crt[cycle-1] = 1
|
||||
|
||||
if op[0] == 'noop': cycle = cycle + 1
|
||||
else:
|
||||
cycle = cycle + 1
|
||||
if (cycle % 40) == 20: strength = strength + reg * cycle
|
||||
if (cycle % 40) in [reg,reg+1,reg+2]: crt[cycle-1] = 1
|
||||
cycle = cycle + 1
|
||||
reg = reg + int(op[1])
|
||||
|
||||
# challenge 1
|
||||
res1 = str(strength)
|
||||
print("challenge 1:" + "\n" + res1 + "\n")
|
||||
|
||||
# challenge 2
|
||||
print("challenge 2:" + "\n")
|
||||
show_crt(crt)
|
||||
|
||||
Reference in new issue
Block a user