Solution for programming assignment 2.