Programming assignment 2 solution