Problem Seven

Could be more efficient, however it runs at an acceptable speed.