day 23 optimize, with help
commitb8eefcdcf9b85185d8707ceaabc83f5704973ca4
authorEric Blake <eblake@redhat.com>
Mon, 22 Jan 2024 17:02:22 +0000 (22 11:02 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 22 Jan 2024 17:25:54 +0000 (22 11:25 -0600)
tree9217a71409aad8f5c95d45bb4d0c0ea42a216cb7
parent8df3962a0930716217cf3e53a445c474108fb491
day 23 optimize, with help

Shamelessly port the DP approach from askalski into m4 (see the link
in the code).  The dynamic programming solution is WAY faster than any
DFS pruning, by exploiting the maximum tree-width into a bounded
linear amount of work per row.  Each row is processed in isolation and
computes the set of all possible downward exits that still form a
valid string of balanced and nested pairs of path components; since
there are a limited number of such strings, pruning is as simple as
rejecting the attempts that don't produce a valid exit string.  This
cuts the solution time to 315ms.

My original DFS solution is still available via -Dalgo=dfs.
2023/day23.m4
times.ods