Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Radiation Search by jmcs
def count(matr, i, j,target):
rows = len(matr)
if i == rows or i <0: return 0
cols = len(matr[0])
if j == cols or j <0: return 0
num = matr[i][j]
matr[i][j] = -1
if target != num or num == -1: return 0
gs = 1 + count(matr,i+1,j,target) + count(matr,i,j+1,target) + count(matr,i,j-1,target) + count(matr,i-1,j,target)
return gs
def checkio(matr):
rows = len(matr)
cols = len(matr[0])
big = [0,0]
for i in range(rows):
for j in range(cols):
num = matr[i][j]
gs= count(matr,i,j, num)
new = [gs,num]
big = big if big[0]>new[0] else new
print(big)
return big
if __name__ == '__main__':
assert 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], 'First'
assert 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], 'Second'
print('All ok')
Oct. 26, 2012