equal
deleted
inserted
replaced
244 |
244 |
245 The combination of two adjacent numbers will cover all possible cases. |
245 The combination of two adjacent numbers will cover all possible cases. |
246 That is to say, given any x, y where both x, and y are in range(2 ** n), |
246 That is to say, given any x, y where both x, and y are in range(2 ** n), |
247 there is an x followed immediately by y in the generated sequence. |
247 there is an x followed immediately by y in the generated sequence. |
248 """ |
248 """ |
249 m = 2 ** n |
249 m = 2**n |
250 |
250 |
251 # Gray Code. See https://en.wikipedia.org/wiki/Gray_code |
251 # Gray Code. See https://en.wikipedia.org/wiki/Gray_code |
252 gray = lambda x: x ^ (x >> 1) |
252 gray = lambda x: x ^ (x >> 1) |
253 reversegray = {gray(i): i for i in range(m)} |
253 reversegray = {gray(i): i for i in range(m)} |
254 |
254 |