11/27
Part 3 of 7 · The shape of the treeLearn and do
One answer carries the count and the shape
There's no need for a second round of messages. Put both values in the same answer: ("answer", count, shape). Each machine stores the pair under the child that sent it, and when every child is in, it builds both:
- the count is 1 plus the children's counts,
- the shape is its id plus the children's shapes in list order.
The root stores both, in self.count and self.tree. Everyone else sends both up.
This is a pattern worth naming. Anything you can compute for a machine from its own value and its children's results travels up in the same pass: a count, a sum, a maximum, the shape. The worked example later counts free disk the same way.
The editor holds the level 1 Machine, with self.tree added and two parts cut out. Write the answer branch of receive and the end of finish_if_done, so one answer carries the count and the shape.