Solve gray code