Did the author overthink it or are the simple solutions not correct?
Did the author overthink it or are the simple solutions not correct?
If you aren't comfortable with recursion, I can see it taking a while.
It's basically a walk down a binary tree with some extra logic. You have to write two recursive functions, one each for (b) and (c) but they have basically the same structure with different return values. The function for (b) can be used for (c) (not the most efficient, but it does work). (d) requires minor modifications to the functions created in (a)-(c) so you can start with copies of the originals and make the change, I think it's a one symbol change in each function, or maybe two.
> Exercise 2.92. By imposing an ordering on variables, extend the polynomial package so that addition and multiplication of polynomials works for polynomials in different variables. (This is not easy!)
2.29 is what I described in my other comment, it's a pair of functions walking a binary tree with conditional logic based on if it's an interior or exterior node, returning either a sum or a true/false value. Which is not hard at all and their time was only 83 minutes. Versus their claimed time of 2400 minutes for 2.92.