Gray code n-th value
Your task
Return the n-th value (0-indexed) of the standard reflected binary Gray code sequence, for non-negative n. Consecutive Gray code values differ in exactly one bit, which makes them useful for error-resistant encoders and in some communication/position-sensing systems. The closed form is simply n XOR (n >> 1). Return that value.
Examples
gray_code(n: int) -> intExample 1
Input
gray_code(3)Output
2