Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #aoc2016_8.py
- input_file_object = open("aoc16_input_8a.txt")
- input_as_string = input_file_object.read()
- input_file_object.close()
- input_separated = input_as_string.split('\n')
- screen_x = 50
- screen_y = 6
- screen = [['.' for x in range(screen_x)] for y in range(screen_y)]
- def rect(x,y):
- for c in range(y):
- #for each column
- for r in range(x):
- screen[c][r] = '#'
- def pushRow(screen,row_index, offset):
- #take a slice of the row that wraps
- chopped = screen[row_index][-offset:]
- #then, going backwards through that list, add it to beginning of row
- for i in range(len(chopped),0,-1):
- screen[row_index].insert(0,chopped[i-1])
- screen[row_index] = screen[row_index][:50]
- return screen
- def pushCol(screen, col_index, offset):
- old_col = []
- new_col = old_col
- for i in range(len(screen)):
- #make a list with the characters from top to bottom
- old_col.append(screen[i][col_index])
- #Now I need to rotate them such that the character at x is now
- #at x+offset.
- chopped = old_col[-offset:]
- for j in range(len(chopped),0,-1):
- new_col.insert(0, chopped[j-1])
- new_col = new_col[:6]
- for k in range(len(screen)):
- screen[k][col_index] = new_col[k]
- ###now to strip down this input###
- input_stripped = []
- for i in range(len(input_separated)):
- input_stripped.append(input_separated[i].split('='))
- for i in range(len(input_stripped)):
- if 'rect' in input_stripped[i][0]:
- input_stripped[i] = input_stripped[i][0].split(' ')
- for i in range(len(input_stripped)):
- if 'rect' in input_stripped[i][0]:
- input_stripped[i][1] = input_stripped[i][1].split('x')
- for i in range(len(input_stripped)):
- if 'rect' in input_stripped[i][0]:
- input_stripped[i].append(int(input_stripped[i][1][0]))
- input_stripped[i].append(int(input_stripped[i][1][1]))
- del input_stripped[i][1]
- ###time to strip rows and columns
- for i in range(len(input_stripped)):
- if 'rotate' in input_stripped[i][0]:
- if 'row' in input_stripped[i][0]:
- input_stripped[i][0] = 'row'
- else:
- input_stripped[i][0] = 'col'
- for i in range(len(input_stripped)):
- if 'rect' in input_stripped[i][0]:
- continue
- if 'by' in input_stripped[i][1]:
- input_stripped[i][1] = input_stripped[i][1].split(' by ')
- for i in range(len(input_stripped)):
- if 'rect' in input_stripped[i][0]:
- continue
- input_stripped[i].append(int(input_stripped[i][1][0]))
- input_stripped[i].append(int(input_stripped[i][1][1]))
- del input_stripped[i][1]
- #okay now the fun part
- for i in range(len(input_stripped)):
- if 'rect' == input_stripped[i][0]:
- rect(input_stripped[i][1], input_stripped[i][2])
- elif 'row' == input_stripped[i][0]:
- screen = pushRow(screen, input_stripped[i][1], input_stripped[i][2])
- elif 'col' == input_stripped[i][0]:
- pushCol(screen, input_stripped[i][1], input_stripped[i][2])
- counter = 0
- for y in range(len(screen)):
- temp = screen[y].count('#')
- counter += temp
- temp = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement