Solution to programming assignment

The following code will solve the Programming Assignment 2 for R
Programming