Solutions to Advent of Code 2017 https://adventofcode.com/2017/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

09.py 614B

12345678910111213141516171819202122
  1. with open('data/09.txt', 'r') as file:
  2. garbage, escaped, depth, score, removed = False, False, 0, 0, 0
  3. for char in file.readline():
  4. if escaped:
  5. escaped = False
  6. elif garbage:
  7. if char == '!':
  8. escaped = True
  9. elif char == '>':
  10. garbage = False
  11. else:
  12. removed += 1
  13. elif char == '<':
  14. garbage = True
  15. elif char == '{':
  16. depth += 1
  17. score += depth
  18. elif char == '}':
  19. depth -= 1
  20. print(f'Part one: {score}')
  21. print(f'Part two: {removed}')