now with animation

This commit is contained in:
OMGOMG 2021-12-10 00:35:01 +01:00
parent 3ff07d3939
commit dfdf652c0c
2 changed files with 14 additions and 1 deletions

View File

@ -7,9 +7,10 @@ def parseline(s):
with open(0) as f:
basegrid = np.asarray([parseline(l) for l in lines(f)])
ic(basegrid)
w, h = basegrid.shape
grid = np.pad(basegrid, (1,1), constant_values=10)
#ic(grid)
ic(grid)
lowest = np.prod([grid[1:w+1,1:h+1] < grid[x:w+x,y:h+y] # bool prod = "all"
for (x, y) in ((2, 1), (1, 2), (0, 1), (1, 0))], axis=0)

View File

@ -17,5 +17,17 @@ with open(0) as f:
if not is_nine[x, y]:
size, _, _, _ = cv.floodFill(is_nine, mask, (y, x), 1)
basins.append(size)
try:
if sys.argv[1] == '-v':
basin_water_ridge = (grid == 9).astype('uint8') + is_nine # 0, 1 or 2
palette = [(x & 255, x >> 8 & 255, x >> 16)
for x in [0x433c34, 0x7f9aa5, 0xae8c67]]
colored = np.transpose(np.asarray(np.vectorize(
lambda x: palette[x])(
basin_water_ridge)), axes=(1, 2, 0)).astype('uint8')
cv.imshow('basins', colored)
cv.waitKey(16)
except IndexError:
pass
print(np.prod(sorted(basins)[-3:]))