solved problem 4

hopefully that's a bit cleaner written than the last
few solutions