aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

a.py (520B) [raw]


      1 #!/usr/bin/env python3
      2 import sys
      3 import re
      4 from collections import defaultdict
      5 
      6 E = defaultdict(list)
      7 
      8 
      9 # Parse in edges
     10 for l in sys.stdin:
     11     a, b = l.strip().split('-')
     12     E[a].append(b)
     13     E[b].append(a)
     14 
     15 smallre = re.compile('[a-z]+')
     16 def issmall(n):
     17     return smallre.match(n)
     18 
     19 paths = 0
     20 def search(n, path):
     21     global paths
     22     if n == 'end':
     23         paths += 1
     24         return
     25     if issmall(n) and n in path:
     26         return
     27     for c in E[n]:
     28         search(c, path + n)
     29 
     30 search("start", "")
     31 
     32 print(paths)