Solution to CodeEval challenge https://www.codeeval.com/open_challenges/48/