Skip to content

Instantly share code, notes, and snippets.

@vesche
Created December 10, 2016 15:44
Show Gist options
  • Save vesche/afbde373470d0310aafc8b504f9b0a74 to your computer and use it in GitHub Desktop.
Save vesche/afbde373470d0310aafc8b504f9b0a74 to your computer and use it in GitHub Desktop.
AoC 2016 Day 7 Part 1
#!/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()
@zhaoshuo88
Copy link

so cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment