Browse Source

finished day 10, really fun :)

main
Luna Lailatova 2 years ago
parent
commit
5efc24252a
  1. 33
      day10-1.py
  2. 36
      day10-2.py
  3. 154
      in.txt
  4. 140
      input10.txt

33
day10-1.py

@ -0,0 +1,33 @@
def check():
if cycle in [20, 60, 100, 140, 180, 220]:
tempa = cycle * register
checkpoints.append(tempa)
with open('input10.txt','r') as f:
inp = f.read().splitlines(keepends=False)
cycle = 0
line = 0
register = 1
checkpoints = []
_sum = 0
while cycle < 220:
ins = inp[line]
line += 1
if 'noop' in ins:
cycle += 1
check()
elif 'addx' in ins:
cycle += 1
check()
cycle += 1
check()
tempa, tempb = ins.split(' ')
register += int(tempb)
for i in checkpoints:
_sum += i
print(_sum)

36
day10-2.py

@ -0,0 +1,36 @@
with open('input10.txt','r') as f:
inp = f.read().splitlines(keepends=False)
line = 0
register = 1
picture = []
executing = 0
pending = 0
for _ in range(6):
curline = []
for i in range(40):
if executing == 0:
register += pending
pending = 0
ins = inp[line]
line += 1
if 'noop' in ins:
executing = 1
elif 'addx' in ins:
tempa, tempb = ins.split(' ')
pending = int(tempb)
executing = 2
if i in [register - 1, register, register + 1]:
curline.append('#')
else:
curline.append('.')
executing -= 1
picture.append(curline)
for i in picture:
row = ''
for j in i:
row += j
print(row)

154
in.txt

@ -1,8 +1,146 @@
R 5 addx 15
U 8 addx -11
L 8 addx 6
D 3 addx -3
R 17 addx 5
D 10 addx -1
L 25 addx -8
U 20 addx 13
addx 4
noop
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx -35
addx 1
addx 24
addx -19
addx 1
addx 16
addx -11
noop
noop
addx 21
addx -15
noop
noop
addx -3
addx 9
addx 1
addx -3
addx 8
addx 1
addx 5
noop
noop
noop
noop
noop
addx -36
noop
addx 1
addx 7
noop
noop
noop
addx 2
addx 6
noop
noop
noop
noop
noop
addx 1
noop
noop
addx 7
addx 1
noop
addx -13
addx 13
addx 7
noop
addx 1
addx -33
noop
noop
noop
addx 2
noop
noop
noop
addx 8
noop
addx -1
addx 2
addx 1
noop
addx 17
addx -9
addx 1
addx 1
addx -3
addx 11
noop
noop
addx 1
noop
addx 1
noop
noop
addx -13
addx -19
addx 1
addx 3
addx 26
addx -30
addx 12
addx -1
addx 3
addx 1
noop
noop
noop
addx -9
addx 18
addx 1
addx 2
noop
noop
addx 9
noop
noop
noop
addx -1
addx 2
addx -37
addx 1
addx 3
noop
addx 15
addx -21
addx 22
addx -6
addx 1
noop
addx 2
addx 1
noop
addx -10
noop
noop
addx 20
addx 1
addx 2
addx 2
addx -6
addx -11
noop
noop
noop

140
input10.txt

@ -0,0 +1,140 @@
noop
addx 5
noop
noop
noop
addx 1
addx 2
addx 5
addx 2
addx 5
noop
noop
noop
noop
noop
addx -12
addx 18
addx -1
noop
addx 3
addx 5
addx -5
addx 7
noop
addx -36
addx 18
addx -16
noop
noop
noop
addx 5
addx 2
addx 5
addx 2
addx 13
addx -6
addx -4
addx 5
addx 2
addx 4
addx -3
addx 2
noop
addx 3
addx 2
addx 5
addx -40
addx 25
addx -22
addx 25
addx -21
addx 5
addx 3
noop
addx 2
addx 19
addx -10
addx -4
noop
addx -4
addx 7
noop
addx 3
addx 2
addx 5
addx 2
addx -26
addx 27
addx -36
noop
noop
noop
noop
addx 4
addx 6
noop
addx 12
addx -11
addx 2
noop
noop
noop
addx 5
addx 5
addx 2
noop
noop
addx 1
addx 2
addx 5
addx 2
addx 1
noop
noop
addx -38
noop
addx 9
addx -4
noop
noop
addx 7
addx 10
addx -9
addx 2
noop
addx -9
addx 14
addx 5
addx 2
addx -24
addx 25
addx 2
addx 5
addx 2
addx -30
addx 31
addx -38
addx 7
noop
noop
noop
addx 1
addx 21
addx -16
addx 8
addx -4
addx 2
addx 3
noop
noop
addx 5
addx -2
addx 5
addx 3
addx -1
addx -1
addx 4
addx 5
addx -38
noop
Loading…
Cancel
Save