This commit is contained in:
Peter Hudec 2018-01-17 23:33:01 +01:00
parent dd3e5b2ace
commit 5614b07d1a
Signed by: peter.hudec
GPG Key ID: 427BD558E277E410
6 changed files with 2095 additions and 0 deletions

2000
07/input.puzzle Normal file

File diff suppressed because it is too large Load Diff

6
07/input.sample01 Normal file
View File

@ -0,0 +1,6 @@
abba[mnop]qrst
abcd[bddb]xyyx
aaaa[qwer]tyui
ioxxoj[asdfgh]zxcvbn
ioxxo[j[asdfgh]z]xcvbn

4
07/input.sample02 Normal file
View File

@ -0,0 +1,4 @@
aba[bab]xyz
xyx[xyx]xyx
aaa[kek]eke
zazbz[bzb]cdb

36
07/part01.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python
import re
import argparse
RE_ABBA = re.compile(r'(\w)(?!\1)(\w)\2\1')
RE_HYPERNET = re.compile(r'\[[^\]]+\]')
def load_file(filename):
with open(filename) as f:
for line in f:
yield line.strip()
def check_ip(data):
for line in RE_HYPERNET.findall(data):
if RE_ABBA.search(line):
return 0
x = RE_ABBA.search(data)
if RE_ABBA.search(data):
return 1
return 0
def main(args):
count = 0
for LINE in load_file(args.input):
count += check_ip(LINE)
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)

48
07/part02.py Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python
import re
import argparse
RE_ABA = re.compile(r'(?=((\w)(?!\2)\w\2))')
RE_HYPERNET = re.compile(r'\[([^\]]+)\]')
def load_file(filename):
with open(filename) as f:
for line in f:
yield line.strip()
def check_ip(data):
def reverse_aba(aba):
return "{}{}{}".format(aba[1], aba[0], aba[1])
aba_all = []
for aba in RE_ABA.findall(data):
aba_all.append(aba[0])
aba_hyper = []
for hyper in RE_HYPERNET.findall(data):
for aba in RE_ABA.findall(hyper):
aba_hyper.append(aba[0])
for aba in aba_hyper:
aba_all.remove(aba)
for aba in aba_hyper:
if reverse_aba(aba) in aba_all:
return 1
return 0
def main(args):
count = 0
for LINE in load_file(args.input):
count += check_ip(LINE)
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)

View File

@ -10,3 +10,4 @@
- **Day 4**: Security Through Obscurity
- **Day 5**: How About a Nice Game of Chess?
- **Day 6**: Signals and Noise
- **Day 7**: Internet Protocol Version 7