-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrosswords.py
More file actions
33 lines (25 loc) · 964 Bytes
/
crosswords.py
File metadata and controls
33 lines (25 loc) · 964 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
with open("crosswords.in","r") as f_in:
n, m = map(int,f_in.readline().split())
crossword = f_in.read().strip("\n").split("\n")
print(n,m)
print(crossword)
clues = []
clue_count = 0
for x in range(n):
for y in range(m):
if crossword[x][y] == '#':
continue
clue = False
# horizontal clue
if (y == 0 or (y > 0 and crossword[x][y-1] == "#")) and (y < m - 2 and crossword[x][y + 1] == "." and crossword[x][y + 2] == "."):
clue = True
# vertical clue
if (x == 0 or (x > 0 and crossword[x-1][y] == "#")) and (x < n - 2 and crossword[x+1][y] == "." and crossword[x+2][y] == "."):
clue = True
if clue:
clues.append([x + 1, y + 1])
clue_count += 1
with open("crosswords.out","w") as f_out:
f_out.write(str(clue_count)+"\n")
for x in clues:
f_out.write(str(x[0]) + " " + str(x[1]) + "\n")