forked from tomkooij/AdventOfCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3.2.py
57 lines (43 loc) · 1.03 KB
/
day3.2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# adventofcode.com
# day 3.1
INPUTFILE = 'input/input3'
TESTCASE1 = '^v'
TESTCASE2 = '^>v<'
TESTCASE3 = '^v^v^v^v^v'
UP = '^'
DOWN = 'v'
LEFT = '<'
RIGHT = '>'
x, y = 0, 0 # santa location
rx, ry = 0, 0 # robosanta location
trip = [] # list of locations
def move(char, x, y):
if char == UP:
y += 1
elif char == DOWN:
y -= 1
elif char == LEFT:
x -= 1
elif char == RIGHT:
x += 1
else:
print "skipping unkown input: ", char
return x, y
with open(INPUTFILE) as f:
inputstr = f.readline()
#inputstr = TESTCASE3
# start position
trip.append((x, y))
for idx, char in enumerate(inputstr, start=1):
if idx % 2:
# santa moves
x, y = move(char, x, y)
trip.append((x, y))
else:
# robo santa moves this turn
rx, ry = move(char, rx, ry)
trip.append((rx, ry))
#print trip
# remove duplicates
trip = set(trip)
print "Santa visited %d unique locations" % len(trip)