correctly calculates word ladder