ProgrammingAssignment 2 solution