Performance improvement

Problem's position is determined with math instead of a loop