Clean up the "hard" Scala exercise, adding a purely functional example solution.