solution to coursera programming assignment