Some utility functions.
Code for problem 34.