A solution to programming assignment 2