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