37 lines
815 B
Python
37 lines
815 B
Python
![]() |
#!/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)
|