This program was a part of a problem set that I had to complete for a programming contest, I am sure there is a better way to