Day 8 - Advent of Code 2016
Working solution for the day 8 puzzles.
Parts One and Two
""" day_08_01_02.py """
# usage: python3 day_08_01_02.py < input
lcd = [list(50 * '.') for _ in range(6)]
while True:
try:
ins = input()
except EOFError:
break
tokens = ins.split()
if tokens[0] == 'rect':
w, h = [int(i) for i in tokens[1].split('x')]
for j in range(h):
lcd[j][:w] = w * '#'
elif tokens[1] == 'row':
row = int(tokens[2].split('=')[1])
shift = int(tokens[4])
text = 2 * lcd[row]
lcd[row] = text[50 - shift:50 - shift + 50]
elif tokens[1] == 'column':
col = int(tokens[2].split('=')[1])
shift = int(tokens[4])
text = 2 * [lcd[j][col] for j in range(6)]
for j in range(6):
lcd[j][col] = text[6 - shift + j]
print(sum((row.count('#') for row in lcd)))
for row in lcd:
print(''.join(row))