Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countbasin(hm,i,j,cnt = 0):
- if hm[i][j] < 9:
- cnt+=1
- hm[i][j]=9
- for x,y in [(0,-1), (0,1), (-1,0), (1,0)]:
- hm,cnt = countbasin(hm,i+x,j+y,cnt)
- return hm,cnt
- hm = [list(map(int,list('9'+i.replace("\n","")+'9'))) for i in open("input.txt").readlines()]
- hm = [[9]*len(hm[0])] + hm + [[9]*len(hm[0])]
- basins = [countbasin(hm,i,j)[1] for i in range(1,len(hm)-1) for j in range(1,len(hm[0])-1) if ((hm[i][j] < hm[i][j-1]) and (hm[i][j] < hm[i][j+1]) and (hm[i][j] < hm[i-1][j]) and (hm[i][j] < hm[i+1][j]))]
- basins.sort(reverse=True)
- print(basins[0]*basins[1]*basins[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement