Gray Code solution