solution to Gray Code