Solution to Problem (4) from Notes 2
(Solution courtesy of Matt Michaud)