-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_print_map.py
44 lines (36 loc) · 1.02 KB
/
scan_print_map.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
#************************************************************
# scan_print_map.py
# Scan a hashi puzzle from stdin, store it in a numpy array,
# and print it out again.
#
import numpy as np
import sys
def main():
code = ".123456789abc"
nrow, ncol, map = scan_map()
for r in range(nrow):
for c in range(ncol):
print(code[map[r][c]],end="")
print()
def scan_map():
text = []
for line in sys.stdin:
row = []
for ch in line:
n = ord(ch)
if n >= 48 and n <= 57: # between '0' and '9'
row.append(n - 48)
elif n >= 97 and n <= 122: # between 'a' and 'z'
row.append(n - 87)
elif ch == '.':
row.append(0)
text.append(row)
nrow = len(text)
ncol = len(text[0])
map = np.zeros((nrow,ncol),dtype=np.int32)
for r in range(nrow):
for c in range(ncol):
map[r,c] = text[r][c]
return nrow, ncol, map
if __name__ == '__main__':
main()