Program4

Code for a question asked in an entrance of a Phd. I think optimization
required.