Solution to problem 54

This one is a little messy. Hopefully I can go back and refactor this at
some point.