Solve Problem 7

I'd like to rewrite this using streams or something similar, but maybe
later. This is good enough for now.