Skip to content

Commit 92f968f

Browse files
committed
added 2016/day08
1 parent 5ba122f commit 92f968f

File tree

4 files changed

+261
-1
lines changed

4 files changed

+261
-1
lines changed

2016/day08/answers.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
128
2+
####..##...##..###...##..###..#..#.#...#.##...##..
3+
#....#..#.#..#.#..#.#..#.#..#.#..#.#...##..#.#..#.
4+
###..#..#.#..#.#..#.#....#..#.####..#.#.#..#.#..#.
5+
#....#..#.####.###..#.##.###..#..#...#..####.#..#.
6+
#....#..#.#..#.#.#..#..#.#....#..#...#..#..#.#..#.
7+
####..##..#..#.#..#..###.#....#..#...#..#..#..##..

2016/day08/input.txt

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
rect 1x1
2+
rotate row y=0 by 7
3+
rect 1x1
4+
rotate row y=0 by 5
5+
rect 1x1
6+
rotate row y=0 by 5
7+
rect 1x1
8+
rotate row y=0 by 2
9+
rect 1x1
10+
rotate row y=0 by 3
11+
rect 1x1
12+
rotate row y=0 by 5
13+
rect 1x1
14+
rotate row y=0 by 3
15+
rect 1x1
16+
rotate row y=0 by 2
17+
rect 1x1
18+
rotate row y=0 by 3
19+
rect 2x1
20+
rotate row y=0 by 7
21+
rect 6x1
22+
rotate row y=0 by 3
23+
rect 2x1
24+
rotate row y=0 by 2
25+
rect 1x2
26+
rotate row y=1 by 10
27+
rotate row y=0 by 3
28+
rotate column x=0 by 1
29+
rect 2x1
30+
rotate column x=20 by 1
31+
rotate column x=15 by 1
32+
rotate column x=5 by 1
33+
rotate row y=1 by 5
34+
rotate row y=0 by 2
35+
rect 1x2
36+
rotate row y=0 by 5
37+
rotate column x=0 by 1
38+
rect 4x1
39+
rotate row y=2 by 15
40+
rotate row y=0 by 5
41+
rotate column x=0 by 1
42+
rect 4x1
43+
rotate row y=2 by 5
44+
rotate row y=0 by 5
45+
rotate column x=0 by 1
46+
rect 4x1
47+
rotate row y=2 by 10
48+
rotate row y=0 by 10
49+
rotate column x=8 by 1
50+
rotate column x=5 by 1
51+
rotate column x=0 by 1
52+
rect 9x1
53+
rotate column x=27 by 1
54+
rotate row y=0 by 5
55+
rotate column x=0 by 1
56+
rect 4x1
57+
rotate column x=42 by 1
58+
rotate column x=40 by 1
59+
rotate column x=22 by 1
60+
rotate column x=17 by 1
61+
rotate column x=12 by 1
62+
rotate column x=7 by 1
63+
rotate column x=2 by 1
64+
rotate row y=3 by 10
65+
rotate row y=2 by 5
66+
rotate row y=1 by 3
67+
rotate row y=0 by 10
68+
rect 1x4
69+
rotate column x=37 by 2
70+
rotate row y=3 by 18
71+
rotate row y=2 by 30
72+
rotate row y=1 by 7
73+
rotate row y=0 by 2
74+
rotate column x=13 by 3
75+
rotate column x=12 by 1
76+
rotate column x=10 by 1
77+
rotate column x=7 by 1
78+
rotate column x=6 by 3
79+
rotate column x=5 by 1
80+
rotate column x=3 by 3
81+
rotate column x=2 by 1
82+
rotate column x=0 by 1
83+
rect 14x1
84+
rotate column x=38 by 3
85+
rotate row y=3 by 12
86+
rotate row y=2 by 10
87+
rotate row y=0 by 10
88+
rotate column x=7 by 1
89+
rotate column x=5 by 1
90+
rotate column x=2 by 1
91+
rotate column x=0 by 1
92+
rect 9x1
93+
rotate row y=4 by 20
94+
rotate row y=3 by 25
95+
rotate row y=2 by 10
96+
rotate row y=0 by 15
97+
rotate column x=12 by 1
98+
rotate column x=10 by 1
99+
rotate column x=8 by 3
100+
rotate column x=7 by 1
101+
rotate column x=5 by 1
102+
rotate column x=3 by 3
103+
rotate column x=2 by 1
104+
rotate column x=0 by 1
105+
rect 14x1
106+
rotate column x=34 by 1
107+
rotate row y=1 by 45
108+
rotate column x=47 by 1
109+
rotate column x=42 by 1
110+
rotate column x=19 by 1
111+
rotate column x=9 by 2
112+
rotate row y=4 by 7
113+
rotate row y=3 by 20
114+
rotate row y=0 by 7
115+
rotate column x=5 by 1
116+
rotate column x=3 by 1
117+
rotate column x=2 by 1
118+
rotate column x=0 by 1
119+
rect 6x1
120+
rotate row y=4 by 8
121+
rotate row y=3 by 5
122+
rotate row y=1 by 5
123+
rotate column x=5 by 1
124+
rotate column x=4 by 1
125+
rotate column x=3 by 2
126+
rotate column x=2 by 1
127+
rotate column x=1 by 3
128+
rotate column x=0 by 1
129+
rect 6x1
130+
rotate column x=36 by 3
131+
rotate column x=25 by 3
132+
rotate column x=18 by 3
133+
rotate column x=11 by 3
134+
rotate column x=3 by 4
135+
rotate row y=4 by 5
136+
rotate row y=3 by 5
137+
rotate row y=2 by 8
138+
rotate row y=1 by 8
139+
rotate row y=0 by 3
140+
rotate column x=3 by 4
141+
rotate column x=0 by 4
142+
rect 4x4
143+
rotate row y=4 by 10
144+
rotate row y=3 by 20
145+
rotate row y=1 by 10
146+
rotate row y=0 by 10
147+
rotate column x=8 by 1
148+
rotate column x=7 by 1
149+
rotate column x=6 by 1
150+
rotate column x=5 by 1
151+
rotate column x=3 by 1
152+
rotate column x=2 by 1
153+
rotate column x=1 by 1
154+
rotate column x=0 by 1
155+
rect 9x1
156+
rotate row y=0 by 40
157+
rotate column x=44 by 1
158+
rotate column x=35 by 5
159+
rotate column x=18 by 5
160+
rotate column x=15 by 3
161+
rotate column x=10 by 5
162+
rotate row y=5 by 15
163+
rotate row y=4 by 10
164+
rotate row y=3 by 40
165+
rotate row y=2 by 20
166+
rotate row y=1 by 45
167+
rotate row y=0 by 35
168+
rotate column x=48 by 1
169+
rotate column x=47 by 5
170+
rotate column x=46 by 5
171+
rotate column x=45 by 1
172+
rotate column x=43 by 1
173+
rotate column x=40 by 1
174+
rotate column x=38 by 2
175+
rotate column x=37 by 3
176+
rotate column x=36 by 2
177+
rotate column x=32 by 2
178+
rotate column x=31 by 2
179+
rotate column x=28 by 1
180+
rotate column x=23 by 3
181+
rotate column x=22 by 3
182+
rotate column x=21 by 5
183+
rotate column x=20 by 1
184+
rotate column x=18 by 1
185+
rotate column x=17 by 3
186+
rotate column x=13 by 1
187+
rotate column x=10 by 1
188+
rotate column x=8 by 1
189+
rotate column x=7 by 5
190+
rotate column x=6 by 5
191+
rotate column x=5 by 1
192+
rotate column x=3 by 5
193+
rotate column x=2 by 5
194+
rotate column x=1 by 5

2016/day08/run.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#! /usr/bin/env python3
2+
3+
def load_data(filename):
4+
with open(filename, 'r') as f:
5+
for line in f:
6+
line = line.rstrip('\n')
7+
yield Rect.parse(line) or RotateRow.parse(line) or RotateColumn.parse(line)
8+
9+
class Base:
10+
def __init__(self, a, b):
11+
self.a = a
12+
self.b = b
13+
14+
@classmethod
15+
def parse(cls, s):
16+
match = re.match(cls.pattern, s)
17+
if match:
18+
return cls(int(match.group('a')), int(match.group('b')))
19+
else:
20+
return None
21+
22+
def __repr__(self):
23+
return f'{self.__class__.__name__}(a={self.a}, b={self.b})'
24+
25+
class Rect(Base):
26+
pattern = r'rect (?P<a>\d+)x(?P<b>\d+)'
27+
28+
def __call__(self, screen):
29+
screen[:self.b,:self.a] = 1
30+
31+
class RotateRow(Base):
32+
pattern = r'rotate row y=(?P<a>\d+) by (?P<b>\d+)'
33+
34+
def __call__(self, screen):
35+
screen[self.a:self.a+1,:] = np.hstack((screen[self.a:self.a+1,-self.b:], screen[self.a:self.a+1,:-self.b]))
36+
37+
class RotateColumn(Base):
38+
pattern = r'rotate column x=(?P<a>\d+) by (?P<b>\d+)'
39+
40+
def __call__(self, screen):
41+
screen[:,self.a:self.a+1] = np.vstack((screen[-self.b:,self.a:self.a+1], screen[:-self.b,self.a:self.a+1]))
42+
43+
# Part One
44+
45+
import re
46+
import numpy as np
47+
48+
screen = np.zeros((6, 50), dtype=int)
49+
50+
for cmd in load_data('input.txt'):
51+
cmd(screen)
52+
53+
print(np.sum(screen))
54+
55+
# Part Two
56+
57+
for line in screen:
58+
print(''.join(map(str, line)).replace('1', '#').replace('0', '.'))
59+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
```
22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
33
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
4-
2016 ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
4+
2016 ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
55
2017 ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
66
2018 ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
77
2019 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ -- +- ++ +- -

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy