Working solution for Project Euler Problem 13