Solution to programming assigment 2.