This commit is contained in:
nim-ka
2022-11-22 21:12:29 +00:00
parent 0485b4f035
commit 1abf42137a
7 changed files with 317 additions and 26 deletions

View File

@@ -4,10 +4,10 @@ function day9(input, part2) {
let lows = grid.findAllIndices((e, pt, g) => g.getAdjNeighbors(pt).every((nb) => e < g.get(nb)))
if (!part2) {
return lows.map((e) => grid.get(e) + 1).sum()
return lows.mapArr((e) => grid.get(e) + 1).sum()
}
let sizes = lows.map((low) => grid.bfs(low, (e, pt, g) => {
let sizes = lows.mapArr((low) => grid.bfs(low, (e, pt, g) => {
return e == 9 || g.get(pt.path.last) < e ? Grid.BFS_STOP : Grid.BFS_CONTINUE
}).filter((e) => e.result == Grid.BFS_CONTINUE).length).sort((a, b) => b - a)