···11+import re
22+import fileinput
33+from utils import parse_line
44+55+WIDTH = 50
66+HEIGHT = 6
77+SCREEN = [[False for _ in range(WIDTH)] for _ in range(HEIGHT)]
88+99+for line in fileinput.input():
1010+ if line.startswith('rect'):
1111+ a, b = parse_line(r'rect (\d+)x(\d+)', line)
1212+1313+ for y in range(b):
1414+ for x in range(a):
1515+ SCREEN[y][x] = True
1616+1717+ else:
1818+ rc, n, offset = parse_line(r'rotate (\w+) .=(\d+) by (\d+)', line)
1919+2020+ if rc == 'row':
2121+ temp = SCREEN[n][:]
2222+ for i, x in enumerate(temp):
2323+ SCREEN[n][(offset+i) % WIDTH] = x
2424+2525+ else:
2626+ temp = [row[n] for row in SCREEN]
2727+ for i, x in enumerate(temp):
2828+ SCREEN[(offset+i) % HEIGHT][n] = x
2929+3030+print "Number of lit pixels: %i" % sum(sum(row) for row in SCREEN)
3131+3232+for row in SCREEN:
3333+ print ''.join('#' if x else ' ' for x in row)
+194
2016/input08.txt
···11+rect 1x1
22+rotate row y=0 by 7
33+rect 1x1
44+rotate row y=0 by 5
55+rect 1x1
66+rotate row y=0 by 5
77+rect 1x1
88+rotate row y=0 by 2
99+rect 1x1
1010+rotate row y=0 by 3
1111+rect 1x1
1212+rotate row y=0 by 5
1313+rect 1x1
1414+rotate row y=0 by 3
1515+rect 1x1
1616+rotate row y=0 by 2
1717+rect 1x1
1818+rotate row y=0 by 3
1919+rect 2x1
2020+rotate row y=0 by 7
2121+rect 6x1
2222+rotate row y=0 by 3
2323+rect 2x1
2424+rotate row y=0 by 2
2525+rect 1x2
2626+rotate row y=1 by 10
2727+rotate row y=0 by 3
2828+rotate column x=0 by 1
2929+rect 2x1
3030+rotate column x=20 by 1
3131+rotate column x=15 by 1
3232+rotate column x=5 by 1
3333+rotate row y=1 by 5
3434+rotate row y=0 by 2
3535+rect 1x2
3636+rotate row y=0 by 5
3737+rotate column x=0 by 1
3838+rect 4x1
3939+rotate row y=2 by 15
4040+rotate row y=0 by 5
4141+rotate column x=0 by 1
4242+rect 4x1
4343+rotate row y=2 by 5
4444+rotate row y=0 by 5
4545+rotate column x=0 by 1
4646+rect 4x1
4747+rotate row y=2 by 10
4848+rotate row y=0 by 10
4949+rotate column x=8 by 1
5050+rotate column x=5 by 1
5151+rotate column x=0 by 1
5252+rect 9x1
5353+rotate column x=27 by 1
5454+rotate row y=0 by 5
5555+rotate column x=0 by 1
5656+rect 4x1
5757+rotate column x=42 by 1
5858+rotate column x=40 by 1
5959+rotate column x=22 by 1
6060+rotate column x=17 by 1
6161+rotate column x=12 by 1
6262+rotate column x=7 by 1
6363+rotate column x=2 by 1
6464+rotate row y=3 by 10
6565+rotate row y=2 by 5
6666+rotate row y=1 by 3
6767+rotate row y=0 by 10
6868+rect 1x4
6969+rotate column x=37 by 2
7070+rotate row y=3 by 18
7171+rotate row y=2 by 30
7272+rotate row y=1 by 7
7373+rotate row y=0 by 2
7474+rotate column x=13 by 3
7575+rotate column x=12 by 1
7676+rotate column x=10 by 1
7777+rotate column x=7 by 1
7878+rotate column x=6 by 3
7979+rotate column x=5 by 1
8080+rotate column x=3 by 3
8181+rotate column x=2 by 1
8282+rotate column x=0 by 1
8383+rect 14x1
8484+rotate column x=38 by 3
8585+rotate row y=3 by 12
8686+rotate row y=2 by 10
8787+rotate row y=0 by 10
8888+rotate column x=7 by 1
8989+rotate column x=5 by 1
9090+rotate column x=2 by 1
9191+rotate column x=0 by 1
9292+rect 9x1
9393+rotate row y=4 by 20
9494+rotate row y=3 by 25
9595+rotate row y=2 by 10
9696+rotate row y=0 by 15
9797+rotate column x=12 by 1
9898+rotate column x=10 by 1
9999+rotate column x=8 by 3
100100+rotate column x=7 by 1
101101+rotate column x=5 by 1
102102+rotate column x=3 by 3
103103+rotate column x=2 by 1
104104+rotate column x=0 by 1
105105+rect 14x1
106106+rotate column x=34 by 1
107107+rotate row y=1 by 45
108108+rotate column x=47 by 1
109109+rotate column x=42 by 1
110110+rotate column x=19 by 1
111111+rotate column x=9 by 2
112112+rotate row y=4 by 7
113113+rotate row y=3 by 20
114114+rotate row y=0 by 7
115115+rotate column x=5 by 1
116116+rotate column x=3 by 1
117117+rotate column x=2 by 1
118118+rotate column x=0 by 1
119119+rect 6x1
120120+rotate row y=4 by 8
121121+rotate row y=3 by 5
122122+rotate row y=1 by 5
123123+rotate column x=5 by 1
124124+rotate column x=4 by 1
125125+rotate column x=3 by 2
126126+rotate column x=2 by 1
127127+rotate column x=1 by 3
128128+rotate column x=0 by 1
129129+rect 6x1
130130+rotate column x=36 by 3
131131+rotate column x=25 by 3
132132+rotate column x=18 by 3
133133+rotate column x=11 by 3
134134+rotate column x=3 by 4
135135+rotate row y=4 by 5
136136+rotate row y=3 by 5
137137+rotate row y=2 by 8
138138+rotate row y=1 by 8
139139+rotate row y=0 by 3
140140+rotate column x=3 by 4
141141+rotate column x=0 by 4
142142+rect 4x4
143143+rotate row y=4 by 10
144144+rotate row y=3 by 20
145145+rotate row y=1 by 10
146146+rotate row y=0 by 10
147147+rotate column x=8 by 1
148148+rotate column x=7 by 1
149149+rotate column x=6 by 1
150150+rotate column x=5 by 1
151151+rotate column x=3 by 1
152152+rotate column x=2 by 1
153153+rotate column x=1 by 1
154154+rotate column x=0 by 1
155155+rect 9x1
156156+rotate row y=0 by 40
157157+rotate column x=44 by 1
158158+rotate column x=35 by 5
159159+rotate column x=18 by 5
160160+rotate column x=15 by 3
161161+rotate column x=10 by 5
162162+rotate row y=5 by 15
163163+rotate row y=4 by 10
164164+rotate row y=3 by 40
165165+rotate row y=2 by 20
166166+rotate row y=1 by 45
167167+rotate row y=0 by 35
168168+rotate column x=48 by 1
169169+rotate column x=47 by 5
170170+rotate column x=46 by 5
171171+rotate column x=45 by 1
172172+rotate column x=43 by 1
173173+rotate column x=40 by 1
174174+rotate column x=38 by 2
175175+rotate column x=37 by 3
176176+rotate column x=36 by 2
177177+rotate column x=32 by 2
178178+rotate column x=31 by 2
179179+rotate column x=28 by 1
180180+rotate column x=23 by 3
181181+rotate column x=22 by 3
182182+rotate column x=21 by 5
183183+rotate column x=20 by 1
184184+rotate column x=18 by 1
185185+rotate column x=17 by 3
186186+rotate column x=13 by 1
187187+rotate column x=10 by 1
188188+rotate column x=8 by 1
189189+rotate column x=7 by 5
190190+rotate column x=6 by 5
191191+rotate column x=5 by 1
192192+rotate column x=3 by 5
193193+rotate column x=2 by 5
194194+rotate column x=1 by 5