Advent of Code 2016 solutions https://adventofcode.com/2016/
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.

02.py 1010B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/python3
  2. import operator
  3. with open('data/02.txt', 'r') as file:
  4. input = [x.strip() for x in file.readlines()]
  5. dirs = {'U': (0, -1), 'D': (0, 1), 'L': (-1, 0), 'R': (1, 0)}
  6. parts = {1: {(0, 0): '1', (1, 0): '2', (2, 0): '3',
  7. (0, 1): '4', (1, 1): '5', (2, 1): '6',
  8. (0, 2): '7', (1, 2): '8', (2, 2): '9'},
  9. 2: { (2, 0): '1',
  10. (1, 1): '2', (2, 1): '3', (3, 1): '4',
  11. (0, 2): '5', (1, 2): '6', (2, 2): '7', (3, 2): '8', (4, 2): '9',
  12. (1, 3): 'A', (2, 3): 'B', (3, 3): 'C',
  13. (2, 4): 'D'}}
  14. for part, keys in parts.items():
  15. pos = list(keys.keys())[list(keys.values()).index('5')]
  16. ans = ''
  17. for line in input:
  18. for move in map(dirs.get, line):
  19. next_pos = tuple(map(operator.add, pos, move))
  20. pos = next_pos if next_pos in keys else pos
  21. ans += keys[pos]
  22. print('Part %s: %s' % (part, ans))