Programming Assignment 2 solution