Solution to rprog-002 assignment 2