This commit is contained in:
Peter Hudec 2018-01-18 00:45:02 +01:00
parent 5614b07d1a
commit f4073c9846
Signed by: peter.hudec
GPG Key ID: 427BD558E277E410
5 changed files with 308 additions and 0 deletions

170
08/input.puzzle Normal file
View File

@ -0,0 +1,170 @@
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 3
rect 1x1
rotate row y=0 by 2
rect 1x1
rotate row y=0 by 3
rect 1x1
rotate row y=0 by 2
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 3
rect 1x1
rotate row y=0 by 2
rect 1x1
rotate row y=0 by 3
rect 2x1
rotate row y=0 by 2
rect 1x2
rotate row y=1 by 5
rotate row y=0 by 3
rect 1x2
rotate column x=30 by 1
rotate column x=25 by 1
rotate column x=10 by 1
rotate row y=1 by 5
rotate row y=0 by 2
rect 1x2
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate row y=2 by 18
rotate row y=0 by 5
rotate column x=0 by 1
rect 3x1
rotate row y=2 by 12
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate column x=20 by 1
rotate row y=2 by 5
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate row y=2 by 15
rotate row y=0 by 15
rotate column x=10 by 1
rotate column x=5 by 1
rotate column x=0 by 1
rect 14x1
rotate column x=37 by 1
rotate column x=23 by 1
rotate column x=7 by 2
rotate row y=3 by 20
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate row y=3 by 5
rotate row y=2 by 2
rotate row y=1 by 4
rotate row y=0 by 4
rect 1x4
rotate column x=35 by 3
rotate column x=18 by 3
rotate column x=13 by 3
rotate row y=3 by 5
rotate row y=2 by 3
rotate row y=1 by 1
rotate row y=0 by 1
rect 1x5
rotate row y=4 by 20
rotate row y=3 by 10
rotate row y=2 by 13
rotate row y=0 by 10
rotate column x=5 by 1
rotate column x=3 by 3
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate row y=4 by 10
rotate row y=3 by 10
rotate row y=1 by 10
rotate row y=0 by 10
rotate column x=7 by 2
rotate column x=5 by 1
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate row y=4 by 20
rotate row y=3 by 12
rotate row y=1 by 15
rotate row y=0 by 10
rotate column x=8 by 2
rotate column x=7 by 1
rotate column x=6 by 2
rotate column x=5 by 1
rotate column x=3 by 1
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate column x=46 by 2
rotate column x=43 by 2
rotate column x=24 by 2
rotate column x=14 by 3
rotate row y=5 by 15
rotate row y=4 by 10
rotate row y=3 by 3
rotate row y=2 by 37
rotate row y=1 by 10
rotate row y=0 by 5
rotate column x=0 by 3
rect 3x3
rotate row y=5 by 15
rotate row y=3 by 10
rotate row y=2 by 10
rotate row y=0 by 10
rotate column x=7 by 3
rotate column x=6 by 3
rotate column x=5 by 1
rotate column x=3 by 1
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate column x=19 by 1
rotate column x=10 by 3
rotate column x=5 by 4
rotate row y=5 by 5
rotate row y=4 by 5
rotate row y=3 by 40
rotate row y=2 by 35
rotate row y=1 by 15
rotate row y=0 by 30
rotate column x=48 by 4
rotate column x=47 by 3
rotate column x=46 by 3
rotate column x=45 by 1
rotate column x=43 by 1
rotate column x=42 by 5
rotate column x=41 by 5
rotate column x=40 by 1
rotate column x=33 by 2
rotate column x=32 by 3
rotate column x=31 by 2
rotate column x=28 by 1
rotate column x=27 by 5
rotate column x=26 by 5
rotate column x=25 by 1
rotate column x=23 by 5
rotate column x=22 by 5
rotate column x=21 by 5
rotate column x=18 by 5
rotate column x=17 by 5
rotate column x=16 by 5
rotate column x=13 by 5
rotate column x=12 by 5
rotate column x=11 by 5
rotate column x=3 by 1
rotate column x=2 by 5
rotate column x=1 by 5
rotate column x=0 by 1

4
08/input.sample01 Normal file
View File

@ -0,0 +1,4 @@
rect 3x2
rotate column x=1 by 1
rotate row y=0 by 4
rotate column x=1 by 1

68
08/part01.py Executable file
View File

@ -0,0 +1,68 @@
#!/usr/bin/env python
import re
import argparse
SIZE_X = 50
SIZE_Y = 6
RE_RECT = re.compile(r'rect (\d+)x(\d+)$')
RE_ROTATE_C = re.compile(r'rotate column x=(\d+) by (\d+)$')
RE_ROTATE_R = re.compile(r'rotate row y=(\d+) by (\d+)$')
def load_file(filename):
with open(filename) as f:
for line in f:
yield line.strip()
def do_rect(display, size_x, size_y):
for x in range(size_x):
for y in range(size_y):
display[y][x] = 1
def do_rotate_row(display, y, p):
p = SIZE_X - p
display[y] = display[y][p:] + display[y][:p]
def do_rotate_column(display, x, p):
data = [display[i][x] for i in range(SIZE_Y)]
p = SIZE_Y - p
data = data[p:] + data[:p]
for i in range(SIZE_Y):
display[i][x] = data[i]
def main(args):
DISPLAY = []
for y in range(SIZE_Y):
line = []
for x in range(SIZE_X):
line.append(0)
DISPLAY.append(line)
for LINE in load_file(args.input):
match = RE_RECT.search(LINE)
if match:
do_rect(DISPLAY, int(match.group(1)), int(match.group(2)))
continue
match = RE_ROTATE_C.search(LINE)
if match:
do_rotate_column(DISPLAY, int(match.group(1)), int(match.group(2)))
continue
match = RE_ROTATE_R.search(LINE)
if match:
do_rotate_row(DISPLAY, int(match.group(1)), int(match.group(2)))
continue
raise Exception("unkown instruction: {}".format(LINE))
count = 0
for y in range(SIZE_Y):
for x in range(SIZE_X):
count += DISPLAY[y][x]
print(count)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='AdventOfCode 2016 Day 01')
parser.add_argument('--input', '-i', action='store', required=True, help='input file')
args = parser.parse_args()
main(args)

65
08/part02.py Executable file
View File

@ -0,0 +1,65 @@
#!/usr/bin/env python
import re
import argparse
SIZE_X = 50
SIZE_Y = 6
RE_RECT = re.compile(r'rect (\d+)x(\d+)$')
RE_ROTATE_C = re.compile(r'rotate column x=(\d+) by (\d+)$')
RE_ROTATE_R = re.compile(r'rotate row y=(\d+) by (\d+)$')
def load_file(filename):
with open(filename) as f:
for line in f:
yield line.strip()
def do_rect(display, size_x, size_y):
for x in range(size_x):
for y in range(size_y):
display[y][x] = 'X'
def do_rotate_row(display, y, p):
p = SIZE_X - p
display[y] = display[y][p:] + display[y][:p]
def do_rotate_column(display, x, p):
data = [display[i][x] for i in range(SIZE_Y)]
p = SIZE_Y - p
data = data[p:] + data[:p]
for i in range(SIZE_Y):
display[i][x] = data[i]
def main(args):
DISPLAY = []
for y in range(SIZE_Y):
line = []
for x in range(SIZE_X):
line.append(" ")
DISPLAY.append(line)
for LINE in load_file(args.input):
match = RE_RECT.search(LINE)
if match:
do_rect(DISPLAY, int(match.group(1)), int(match.group(2)))
continue
match = RE_ROTATE_C.search(LINE)
if match:
do_rotate_column(DISPLAY, int(match.group(1)), int(match.group(2)))
continue
match = RE_ROTATE_R.search(LINE)
if match:
do_rotate_row(DISPLAY, int(match.group(1)), int(match.group(2)))
continue
raise Exception("unkown instruction: {}".format(LINE))
for y in range(SIZE_Y):
print("".join(DISPLAY[y]))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='AdventOfCode 2016 Day 01')
parser.add_argument('--input', '-i', action='store', required=True, help='input file')
args = parser.parse_args()
main(args)

View File

@ -11,3 +11,4 @@
- **Day 5**: How About a Nice Game of Chess?
- **Day 6**: Signals and Noise
- **Day 7**: Internet Protocol Version 7
- **Day 8**: Two-Factor Authentication