solve the gray code problem.