Learn how to use structural pattern matching (the match statement) to work recursively through tree-like structures.
Grab a piece of paper and try to fold your way out of this problem.