-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathpathtracing.py
executable file
·48 lines (46 loc) · 1.09 KB
/
pathtracing.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
#!/usr/bin/env python2
# https://open.kattis.com/problems/pathtracing
import sys
x = 0
y = 0
min_x, max_x = x, x
min_y, max_y = y, y
seq = [(0, 0)]
while True:
try:
line = raw_input()
if line == 'down':
y -= 1
elif line == 'up':
y += 1
elif line == 'left':
x -= 1
elif line == 'right':
x += 1
else:
print >> sys.stderr, line
continue
min_x = min(x, min_x)
max_x = max(x, max_x)
min_y = min(y, min_y)
max_y = max(y, max_y)
seq.append((x, y))
except :
break
seq = [(x - min_x, max_y - y) for (x, y) in seq]
max_x -= min_x
max_y -= min_y
print '#' * (max_x + 3)
for y in range(max_y + 1):
sys.stdout.write('#')
for x in range(max_x + 1):
if (x, y) == seq[0]:
sys.stdout.write('S')
elif (x, y) == seq[-1]:
sys.stdout.write('E')
elif (x, y) in seq:
sys.stdout.write('*')
else:
sys.stdout.write(' ')
sys.stdout.write('#\n')
print '#' * (max_x + 3)