Solution to 2nd programming assigment