Advertisement
Guest User

Reibello AoC 8

a guest
Dec 8th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.18 KB | None | 0 0
  1. #aoc2016_8.py
  2. input_file_object = open("aoc16_input_8a.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. screen_x = 50
  9. screen_y = 6
  10.  
  11. screen = [['.' for x in range(screen_x)] for y in range(screen_y)]
  12.  
  13. def rect(x,y):
  14.     for c in range(y):
  15.         #for each column
  16.         for r in range(x):
  17.             screen[c][r] = '#'
  18.  
  19. def pushRow(screen,row_index, offset):
  20.     #take a slice of the row that wraps
  21.     chopped = screen[row_index][-offset:]
  22.     #then, going backwards through that list, add it to beginning of row
  23.     for i in range(len(chopped),0,-1):
  24.         screen[row_index].insert(0,chopped[i-1])
  25.    
  26.     screen[row_index] = screen[row_index][:50]
  27.     return screen
  28.  
  29. def pushCol(screen, col_index, offset):
  30.     old_col = []
  31.     new_col = old_col
  32.     for i in range(len(screen)):
  33.         #make a list with the characters from top to bottom
  34.         old_col.append(screen[i][col_index])
  35.     #Now I need to rotate them such that the character at x is now
  36.     #at x+offset.
  37.     chopped = old_col[-offset:]
  38.     for j in range(len(chopped),0,-1):
  39.         new_col.insert(0, chopped[j-1])
  40.         new_col = new_col[:6]
  41.     for k in range(len(screen)):
  42.         screen[k][col_index] = new_col[k]
  43.  
  44. ###now to strip down this input###
  45. input_stripped = []
  46. for i in range(len(input_separated)):
  47.     input_stripped.append(input_separated[i].split('='))
  48.  
  49. for i in range(len(input_stripped)):
  50.     if 'rect' in input_stripped[i][0]:
  51.         input_stripped[i] =  input_stripped[i][0].split(' ')
  52.  
  53. for i in range(len(input_stripped)):
  54.     if 'rect' in input_stripped[i][0]:
  55.         input_stripped[i][1] = input_stripped[i][1].split('x')
  56.  
  57. for i in range(len(input_stripped)):
  58.     if 'rect' in input_stripped[i][0]:
  59.         input_stripped[i].append(int(input_stripped[i][1][0]))
  60.         input_stripped[i].append(int(input_stripped[i][1][1]))
  61.         del input_stripped[i][1]
  62.  
  63. ###time to strip rows and columns
  64.  
  65. for i in range(len(input_stripped)):
  66.     if 'rotate' in input_stripped[i][0]:
  67.         if 'row' in input_stripped[i][0]:
  68.             input_stripped[i][0] = 'row'
  69.         else:
  70.             input_stripped[i][0] = 'col'
  71.  
  72. for i in range(len(input_stripped)):
  73.     if 'rect' in input_stripped[i][0]:
  74.         continue
  75.     if 'by' in input_stripped[i][1]:
  76.         input_stripped[i][1] = input_stripped[i][1].split(' by ')
  77.  
  78.  
  79. for i in range(len(input_stripped)):
  80.     if 'rect' in input_stripped[i][0]:
  81.         continue
  82.     input_stripped[i].append(int(input_stripped[i][1][0]))
  83.     input_stripped[i].append(int(input_stripped[i][1][1]))
  84.     del input_stripped[i][1]
  85.  
  86. #okay now the fun part
  87.  
  88. for i in range(len(input_stripped)):
  89.     if 'rect' == input_stripped[i][0]:
  90.         rect(input_stripped[i][1], input_stripped[i][2])
  91.     elif 'row' == input_stripped[i][0]:
  92.         screen = pushRow(screen, input_stripped[i][1], input_stripped[i][2])
  93.     elif 'col' == input_stripped[i][0]:
  94.         pushCol(screen, input_stripped[i][1], input_stripped[i][2])
  95.  
  96. counter = 0
  97. for y in range(len(screen)):
  98.     temp = screen[y].count('#')
  99.     counter += temp
  100.     temp = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement