Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Calculate Islands by m.dziardziel
def kwadrat(mapa,y,x,size_w,size_k):
a=y-1
b=y+2
c=x-1
d=x+2
if a < 0:
a=0
if c < 0:
c=0
if b >= size_w:
b=size_w
if d >= size_k:
d=size_k
for e in range(a,b):
for f in range(c,d):
if mapa[e][f]!=0 and mapa[e][f]!=1:
return mapa[e][f]
return 0
def napraw(mapa,y,x,size_w,size_k):
odp=[]
a=y-1
b=y+2
c=x-1
d=x+2
if a < 0:
a=0
if c < 0:
c=0
if b >= size_w:
b=size_w
if d >= size_k:
d=size_k
for e in range(a,b):
for f in range(c,d):
if mapa[e][f]!= mapa[y][x] and mapa[y][x]!=0 and mapa[e][f]!= 0:
odp.append(e)
odp.append(f)
return odp
return False
def checkio(land_map):
x=0
y=0
licze=[]
stopien=2
size_w=len(land_map)
size_k=len(land_map[0])
for a in range(0,size_w):
for b in range(0,size_k):
if land_map[a][b]==1:
if kwadrat(land_map,a,b,size_w,size_k)>0:
land_map[a][b]=kwadrat(land_map,a,b,size_w,size_k)
elif kwadrat(land_map,a,b,size_w,size_k)==0:
land_map[a][b]=stopien
stopien=stopien+1
licze.append(0)
for a in range(size_w-1,-1,-1):
for b in range(size_k-1,-1,-1):
if napraw(land_map,a,b,size_w,size_k)!=False:
odp=napraw(land_map,a,b,size_w,size_k)
land_map[odp[0]][odp[1]]=land_map[a][b]
for a in range(0,size_w):
for b in range(0,size_k):
if land_map[a][b]!=0:
licze[land_map[a][b]-2]=licze[land_map[a][b]-2]+1
licze.sort()
bbb=0
while licze[bbb]==0:
bbb=bbb+1
licze.remove(0)
if bbb==len(licze):
break
return licze
Oct. 30, 2016