solution for Gray Code