Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #aoc 2016 12a
- input_file_object = open("aoc16_input_12a.txt")
- input_as_string = input_file_object.read()
- input_file_object.close()
- input_separated = input_as_string.split('\n')
- input_final = []
- def cpy(x, y):
- #print('cpy',x, y)
- if x.isdigit():
- x = int(x)
- else:
- x = reg[x]
- reg[y] = x
- def inc(x):
- #print('inc',x,)
- reg[x] +=1
- def dec(x):
- #print('dec', x)
- reg[x] -=1
- def jnz(val, dist, iterator):
- if val.isdigit() and val != '0':
- return int(dist)
- elif reg[val] != 0:
- return int(dist)
- else:
- return 1
- for x in range(len(input_separated)):
- input_final.append(input_separated[x].split(' '))
- reg = {'a':0, 'b':0, 'c':1, 'd':0}
- x=0
- while x < len(input_final):
- if input_final[x][0] == 'cpy':
- cpy(input_final[x][1], input_final[x][2])
- x +=1
- elif input_final[x][0] == 'inc':
- inc(input_final[x][1])
- x+=1
- elif input_final[x][0] == 'dec':
- dec(input_final[x][1])
- x+=1
- elif input_final[x][0] == 'jnz':
- x+= jnz(input_final[x][1],input_final[x][2],x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement