20 hours later…
21:11
I can guarantee that this terminates, by the way. Recursion depth that replaces the tree is limited by x, which only strictly decreases, so it suffices to show that traversing each individual tree terminates:
21:37
Traversing through a branch node with value 0 at index i will cause the number of 0s in D to increase by C_i * (d_i-1) -1. Leaf nodes will cause a decrease of 1 to the same quantity.
In the simplest case, where there are no 0 nodes, it's trivial to see that traversal will complete; the tree gets read as a large series of nested for loops.
In a tree with 0s only as leaves, it is also trivial to see that no expansion of the tree occurs, and execution will terminate.
(the above is why I do replacements with t(x,3) before recursing, so I can guarantee to not get stuck like that and miss out on growth.)
Now for a slightly more complicated case, with one branch 0. It will replace all the leaf nodes after it in traversal order with 0s, but after that the tree becomes one with only 0s as leaves again.
« first day (48 days earlier) ← previous day next day → last day (204 days later) »