Solution for generating gray code.