'Unranks an n-bit sized Gray code of rank k. This method exists
so that a derivative GrayCode class can define its own code of
a given rank.
The string here is generated in reverse order to allow for tail-call
optimization.
Examples
>>> from sympy.combinatorics.graycode import GrayCode
>>> GrayCode(5, rank=3).current
\'00010\'
>>> GrayCode.unrank(5, 3)
\'00010\'
See Also
rank'

@classmethod
def unrank(self, n, rank):

    def _unrank(k, n):
        if (n == 1):
            return str((k % 2))
        m = (2 ** (n - 1))
        if (k < m):
            return ('0' + _unrank(k, (n - 1)))
        return ('1' + _unrank(((m - (k % m)) - 1), (n - 1)))
    return _unrank(rank, n)
