Solution to question from projecteular.net