Solution to problem 37.

Not 100% happy with this solution yet, still takes too long (~16
seconds).
Shell of 38.