3 hours later…
16:49
t(x,y) translates a number into a tree of 1s and 0s with y children for each node. It pads enough 0s so that the last row is all 0s and that the tree is full (all filled out ot the same level). t(0,x) = [0], which denotes a tree node
tree
with tree.v == 0
and no valid values for tree[i]
because it's a leaf node.
t(3,3) returns a tree with three layers: the top node has value 1, its first child has value 1, and all the other nodes have value 0
More in depth on t(3,3): we first represent 3 as its binary representation, 11_2. That has length 2, which can't possibly fill all 3 children. The lengths of flat representations of valid trees are sums of all powers of 3: 1, 1+3^1=4, 4+3^2=13, 13+3^3=40, etc
The first one that we could fill this to is two levels, which requires length 4, but that would put a 1 in the last level so we need to pad to 13 instead
We add each group as children to the first breadth-first-search-wise node we haven't added children to yet. That means "100" is added as the root node's children, then 000 is added to the child 1, then 000 is added to the first child 0, and then 000 is added to the second child 0, and then there's no groups left to add
« first day (49 days earlier) ← previous day next day → last day (203 days later) »