Solution to programming assignment 2