from sympy.combinatorics import GrayCode >>> a = GrayCode(5) >>> a.n 5 r