Advertisement
Guest User

Reibello AoC 12

a guest
Dec 12th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #aoc 2016 12a
  2. input_file_object = open("aoc16_input_12a.txt")
  3. input_as_string = input_file_object.read()
  4. input_file_object.close()
  5.  
  6. input_separated = input_as_string.split('\n')
  7.  
  8.  
  9. input_final = []
  10.  
  11. def cpy(x, y):
  12.     #print('cpy',x, y)
  13.     if x.isdigit():
  14.         x = int(x)
  15.     else:
  16.         x = reg[x]
  17.     reg[y] = x
  18.  
  19. def inc(x):
  20.     #print('inc',x,)
  21.     reg[x] +=1
  22. def dec(x):
  23.     #print('dec', x)
  24.     reg[x] -=1
  25. def jnz(val, dist, iterator):
  26.     if val.isdigit() and val != '0':
  27.         return int(dist)
  28.     elif reg[val] != 0:
  29.         return int(dist)
  30.     else:
  31.         return 1
  32.  
  33.    
  34. for x in range(len(input_separated)):
  35.     input_final.append(input_separated[x].split(' '))
  36.  
  37.  
  38. reg = {'a':0, 'b':0, 'c':1, 'd':0}
  39.  
  40. x=0
  41.  
  42. while x < len(input_final):
  43.     if input_final[x][0] == 'cpy':
  44.         cpy(input_final[x][1], input_final[x][2])
  45.         x +=1
  46.     elif input_final[x][0] == 'inc':
  47.         inc(input_final[x][1])
  48.         x+=1
  49.     elif input_final[x][0] == 'dec':
  50.         dec(input_final[x][1])
  51.         x+=1
  52.     elif input_final[x][0] == 'jnz':
  53.         x+= jnz(input_final[x][1],input_final[x][2],x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement