day 09
This commit is contained in:
parent
f4073c9846
commit
0d591796a6
1
09/input.puzzle
Normal file
1
09/input.puzzle
Normal file
File diff suppressed because one or more lines are too long
6
09/input.sample01
Normal file
6
09/input.sample01
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
ADVENT
|
||||||
|
A(1x5)BC
|
||||||
|
(3x3)XYZ
|
||||||
|
A(2x2)BCD(2x2)EFG
|
||||||
|
(6x1)(1x3)A
|
||||||
|
X(8x2)(3x3)ABCY
|
4
09/input.sample02
Normal file
4
09/input.sample02
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(3x3)XYZ
|
||||||
|
X(8x2)(3x3)ABCY
|
||||||
|
(27x12)(20x12)(13x14)(7x10)(1x12)A
|
||||||
|
(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN
|
40
09/part01.py
Executable file
40
09/part01.py
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import re
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
# 11038 - too low
|
||||||
|
|
||||||
|
RE_COMPRESS= re.compile(r'^([^\(]*)\((\d+)x(\d+)\)(.*)$')
|
||||||
|
|
||||||
|
def load_file(filename):
|
||||||
|
with open(filename) as f:
|
||||||
|
for line in f:
|
||||||
|
yield line.strip()
|
||||||
|
|
||||||
|
def line_length(data):
|
||||||
|
length = 0
|
||||||
|
match = RE_COMPRESS.search(data)
|
||||||
|
while match:
|
||||||
|
size = int(match.group(2))
|
||||||
|
rep = int(match.group(3))
|
||||||
|
length += len(match.group(1))
|
||||||
|
length += size * rep
|
||||||
|
data = match.group(4)[size:]
|
||||||
|
match = RE_COMPRESS.search(data)
|
||||||
|
length += len(data)
|
||||||
|
|
||||||
|
return length
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
length = 0
|
||||||
|
for LINE in load_file(args.input):
|
||||||
|
length += line_length(LINE)
|
||||||
|
print(length)
|
||||||
|
|
||||||
|
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)
|
40
09/part02.py
Executable file
40
09/part02.py
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import re
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
# 11038 - too low
|
||||||
|
|
||||||
|
RE_COMPRESS= re.compile(r'^([^\(]*)\((\d+)x(\d+)\)(.*)$')
|
||||||
|
|
||||||
|
def load_file(filename):
|
||||||
|
with open(filename) as f:
|
||||||
|
for line in f:
|
||||||
|
yield line.strip()
|
||||||
|
|
||||||
|
def line_length(data):
|
||||||
|
length = 0
|
||||||
|
match = RE_COMPRESS.search(data)
|
||||||
|
while match:
|
||||||
|
size = int(match.group(2))
|
||||||
|
rep = int(match.group(3))
|
||||||
|
length += len(match.group(1))
|
||||||
|
length += rep*line_length(match.group(4)[:size])
|
||||||
|
data = match.group(4)[size:]
|
||||||
|
match = RE_COMPRESS.search(data)
|
||||||
|
length += len(data)
|
||||||
|
|
||||||
|
return length
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
length = 0
|
||||||
|
for LINE in load_file(args.input):
|
||||||
|
length += line_length(LINE)
|
||||||
|
print(length)
|
||||||
|
|
||||||
|
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)
|
Loading…
x
Reference in New Issue
Block a user