Skip to content

Instantly share code, notes, and snippets.

@oquno
Created February 19, 2010 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oquno/309124 to your computer and use it in GitHub Desktop.
Save oquno/309124 to your computer and use it in GitHub Desktop.
def create_cell():
cell =[]
for line in open('p.txt', 'r'):
line = list(line.rstrip())
cell.append(line)
return cell
def chaise(cell, x, y):
if cell[x][y] == 'c':
return False
pre = cell[x][y]
cell[x][y] = 'c'
point = 1
if(x != 0):
if pre == cell[x-1][y]:
point += chaise(cell, x-1, y)
if(y != 0):
if pre == cell[x][y-1]:
point += chaise(cell, x, y-1)
if(x != len(cell[0])-1):
if pre == cell[x+1][y]:
point += chaise(cell, x+1, y)
if(y != len(cell)-1):
if pre == cell[x][y+1]:
point += chaise(cell, x, y+1)
return point
def calc_result():
cell = create_cell()
result = [[0, 0, 0]]
for x in range(0, len(cell)):
for y in range(0, len(cell[0])):
p = chaise(cell, x, y)
if p >= result[0][2]:
if(result[0] != p):
result = []
result.append([x, y, p])
return result
def print_count(result):
cell = create_cell()
for i in range(0, len(result)):
chaise(cell, result[i][0], result[i][1])
for i in range(0, len(cell)):
count = 0
for j in range(0, len(cell[i])):
if cell[i][j] == 'c':
count+=1
print count
result = calc_result()
print_count(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment