Minor optimization on speed for day 23.
This commit is contained in:
parent
12d2e88da1
commit
6b904bb42c
@ -209,6 +209,7 @@ fun main() {
|
||||
pos = pos.translate(nextDirs.single())
|
||||
if (pos == endPos) {
|
||||
node.edges.add(relLen + 1 to endNode)
|
||||
endNode.edges.add(relLen + 1 to node)
|
||||
break
|
||||
}
|
||||
} else {
|
||||
@ -222,6 +223,16 @@ fun main() {
|
||||
}
|
||||
} while (nextDirs.size == 1)
|
||||
}
|
||||
|
||||
// optimize endnode path
|
||||
var cNode: GNode = endNode
|
||||
var pNode = cNode
|
||||
while (cNode.edges.size == 1) {
|
||||
pNode = cNode
|
||||
cNode = cNode.edges.single().second
|
||||
}
|
||||
cNode.edges.removeIf { it.second != pNode }
|
||||
|
||||
return rec(endNode, startNode, 0, Array(grid.height) { BooleanArray(grid.width) })
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user