Solution to the "following digit" problem.