-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
54 lines (48 loc) · 1011 Bytes
/
visualize.py
File metadata and controls
54 lines (48 loc) · 1011 Bytes
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
import matplotlib.pyplot as plt
import sys
from copy import deepcopy
import numpy as np
def showPNG(grid):
plt.figure(figsize=(10, 5))
plt.imshow(grid, cmap=plt.cm.CMRmap, interpolation='nearest')
plt.xticks([]), plt.yticks([])
plt.show()
grid = np.loadtxt(sys.argv[1], dtype=int)
if sys.argv[1] != sys.argv[-1]:
nr = len(grid)
nc = len(grid[0])
x,y = 0,0
for i in range(nr):
for j in range(nc):
if grid[i][j] == 2:
x,y = i,j
grid[i][j] = 3
break
path = []
with open(sys.argv[2]) as f:
for line in f:
path = deepcopy(line.split())
# path = [int(z) for z in path]
for i in path:
if i == 'N':
x -= 1
elif i == 'E':
y += 1
elif i == 'W':
y -= 1
else:
x += 1
grid[x][y] = 2
grid[x][y] = 4
showPNG(grid)
else:
nr = len(grid)
nc = len(grid[0])
x,y = 0,0
for i in range(nr):
for j in range(nc):
if grid[i][j] == 2:
grid[i][j] = 3
elif grid[i][j] == 3:
grid[i][j] = 4
showPNG(grid)