Advertisement
Guest User

day 11

a guest
Dec 10th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import Intcode
  2. code = list(map(int, open("input.txt", "r").read().strip().split(","))) + [0]*10000000
  3.  
  4. painted = []
  5. x = 500
  6. y = 500
  7. board = [[0]*1001]*1001
  8. index = 0
  9. directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
  10.  
  11. c = Intcode.Intcode_Computer(code, 0)
  12. while not c.halted:
  13.     c.inputs.append(board[x][y])
  14.     for i in range(2):
  15.         c.run()
  16.     paint = c.outputs[-2]
  17.     turn = c.outputs[-1]
  18.    
  19.     board[x][y] = paint
  20.    
  21.     if((x, y) not in painted):
  22.         painted.append((x, y))
  23.        
  24.     if(turn == 1):
  25.         index += 1
  26.     if(turn == 0):
  27.         index -= 1
  28.     if(index > 3):
  29.         index = 0
  30.     if(index < 0):
  31.         index = 3
  32.        
  33.     x += directions[index][0]
  34.     y += directions[index][1]
  35.    
  36. print(len(painted))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement