adventofcode

https://adventofcode.com/
Log | Files | Refs

puzzle9.py (672B)


      1 from sets import Set
      2 
      3 with open('files/puzzle9.txt') as f:
      4     stream = list(f.read())
      5 
      6 garbage = False
      7 skip = False
      8 depth = 0
      9 total = 0
     10 garbage_characters = 0
     11 
     12 for char in stream:
     13     if garbage:
     14         if skip:
     15             skip = False
     16         else:
     17             if char == '!':
     18                 skip = True
     19                 continue
     20             if char == '>':
     21                 garbage = False
     22             else:
     23                 garbage_characters += 1
     24     else:
     25         if char == '{':
     26             depth += 1
     27             total += depth
     28         if char == '}':
     29             depth -= 1
     30         if char == '<':
     31             garbage = True
     32 
     33 print total
     34 print garbage_characters