-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrossword.py
32 lines (24 loc) · 1.1 KB
/
crossword.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
grid = ['WBWBWBWBWBWBWBW', 'WWWWWWWBWWWWWWW', 'WBWBWBWBWBWBWBW', 'WWBWWWWWWWWWWWW', 'WBWBWBWBWBWBWBW', 'WWWWWWWBBWWWWWW', 'WBWBBBWBWBWBWBW',
'BWWWWWWWWWWWWWB', 'WBWBWBWBWBBBWBW', 'WWWWWWBBWWWWWWW', 'WBWBWBWBWBWBBBW', 'WWWWWWWWWWWWWWW', 'WBWBWBWBWBWBWBW', 'WWWWWWWBWWWWWWW', 'WBWBWBWBWBWBWBW']
BLACK = 'B'
WHITE = 'W'
SEQUENCE = BLACK+WHITE+WHITE
def addBlacksAround(grid):
width = len(grid[0])
newGrid = [BLACK+row+BLACK for row in grid]
newGrid.append((width+2)*BLACK)
newGrid.insert(0, (width+2)*BLACK)
return newGrid
def numberGrid(grid):
positionsOfNumbers = []
number = 1
width = len(grid[0])
def sequenceFound(row, col):
return grid[row][col-1]+grid[row][col]+grid[row][col+1] == SEQUENCE or grid[row-1][col]+grid[row][col]+grid[row+1][col] == SEQUENCE
for row in range(1, width-1):
for col in range(1, width-1):
if sequenceFound(row, col):
positionsOfNumbers.append((row-1, col-1, number))
number += 1
return positionsOfNumbers
print(numberGrid(addBlacksAround(grid)))