Solution for Gray Code