solved Problem 14 on Project Euler, needs to be optimized further