adding project euler solution 31, which is extremely ugly and needs refactoring