Problem 16
Problem 16 - neater functional solution after looking at solutions on line