optimized loops in problem 011