Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Radiation Search by yumax
# migrated from python 2.7
def checkio(l):
n = len(l)
flags = [[0 for i in range(n)] for i in range(n)]
def search(x, y, value):
if not (0 <= x < n) or not (0 <= y < n):
return 0
if flags[x][y]:
return 0
current = l[x][y]
if current == value:
flags[x][y] = 1
res = 1
res += search(x-1, y, current)
res += search(x+1, y, current)
res += search(x, y-1, current)
res += search(x, y+1, current)
return res
return 0
res = max([search(x, y, l[x][y]), l[x][y]] for x in range(n) for y in range(n))
return res
if checkio([
[1,2,3,4,5],
[1,1,1,2,3],
[1,1,1,2,2],
[1,2,2,2,1],
[1,1,1,1,1]
])==[14,1]: print("First done")
if checkio([[2, 1, 2, 2, 2, 4],
[2, 5, 2, 2, 2, 2],
[2, 5, 4, 2, 2, 2],
[2, 5, 2, 2, 4, 2],
[2, 4, 2, 2, 2, 2],
[2, 2, 4, 4, 2, 2]])==[19,2]:print("Second Done")
Nov. 13, 2010
Comments: