ProgrammingAssignment2 solution