Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Enhanced solution in Clear category for Calculate Islands by Ylliw
def checkio(land_map):
same_island=lambda l,island:any([(x-l[0])**2+(y-l[1])**2<=2 for x,y in island])
sizes=[]
lands=[[i,j] for i,row in enumerate(land_map) for j,land in enumerate(row) if land]
print (lands)
while lands:
#still one island
island=[lands.pop()]
old_size,size=0,1
while old_size!=size:
old_size=size
for i,land in enumerate(lands):
if same_island(land,island):island+=[lands.pop(i)]
size=len(island)
sizes+=[size]
return sorted(sizes)
Dec. 8, 2017