Question DSA-BIT-0065
HardWhat is the output of this code?
def gray(n):
return [i ^ (i >> 1) for i in range(1 << n)]
g = gray(3)
print(g, all(bin(g[i] ^ g[i + 1]).count("1") == 1 for i in range(len(g) - 1)))
- A.
[0, 2, 3, 1, 5, 7, 6, 4] True
- B.
[0, 1, 3, 2, 6, 7, 5, 4] False
- C.
Sign up free to see the answer and a step-by-step explanation.