Solved problem 7

Sloppy, but not a great deal of room for optimisation.