Problem 27. Kinda like this solution.