Created
December 10, 2016 15:44
-
-
Save vesche/afbde373470d0310aafc8b504f9b0a74 to your computer and use it in GitHub Desktop.
AoC 2016 Day 7 Part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
###################################### | |
# Advent of Code 2016, Day 07 - Part 1 | |
# https://github.com/vesche | |
###################################### | |
import re | |
def abba(s): | |
chunks = [s[i:i+4] for i in range(0, len(s)) if len(s[i:i+4]) == 4] | |
for c in chunks: | |
if (c[0] != c[1]) and (c[:2] == c[2:][::-1]): | |
return True | |
def main(): | |
valid = 0 | |
with open("day07_input.txt") as f: | |
for addr in f.read().splitlines(): | |
front, hypernet, back = re.search(r"(\w+)\[(\w+)\](\w+)", | |
addr).group(1, 2, 3) | |
if (abba(front) or abba(back)) and not abba(hypernet): | |
valid += 1 | |
return valid | |
if __name__ == "__main__": | |
print main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so cool