day 09
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,6 @@
|
|||||||
|
ADVENT
|
||||||
|
A(1x5)BC
|
||||||
|
(3x3)XYZ
|
||||||
|
A(2x2)BCD(2x2)EFG
|
||||||
|
(6x1)(1x3)A
|
||||||
|
X(8x2)(3x3)ABCY
|
||||||
@@ -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
|
||||||
Executable
+40
@@ -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)
|
||||||
Executable
+40
@@ -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)
|
||||||
@@ -12,3 +12,4 @@
|
|||||||
- **Day 6**: Signals and Noise
|
- **Day 6**: Signals and Noise
|
||||||
- **Day 7**: Internet Protocol Version 7
|
- **Day 7**: Internet Protocol Version 7
|
||||||
- **Day 8**: Two-Factor Authentication
|
- **Day 8**: Two-Factor Authentication
|
||||||
|
- **Day 9**: Explosives in Cyberspace
|
||||||
|
|||||||
Reference in New Issue
Block a user