Solution to problem 30

It's a little ugly, but it works.