Uploaded question 4

The program takes a second or two to complete.  I feel that it could be
written faster, I will be coming back to this.