Solution to ProgrammingAssignment 2