Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Another complex solution in Creative category for Radiation Search by veky
def checkio(matrix):
n=len(matrix)
d={}
for i in range(n):
for j in range(n):
d[i+j*1j]=matrix[i][j]
def s(z):
d[z]*=-1
m=1
while True:
oldm=m
for w in d:
if d[w]<0:
for k in range(4):
if d.get(w+1j**k)==-d[w]:
d[w+1j**k]*=-1
m+=1
if oldm==m: break
for w in d:
d[w]=abs(d[w])
return [m,d[z]]
return max(s(i+j*1j) for i in range(n) for j in range(n))
#These "asserts" using only for self-checking and not necessary for auto-testing
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], "14 of 1"
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], '19 of 2'
May 16, 2013
Comments: