def calc_set(pos, n):
  """
  Computes the subset of {1, 2, ..., `n`} with given rank `pos` 
  in the ordering induces by gray ordering of indicator vectors.
  """
  binary = [1 & (pos >> (n - k - 1)) for k in range(n)]
  assoc_seq = list(map(lambda x: x[0] ^ x[1], zip([0] + binary[:-1], binary)))
  return [x + 1 for x in range(n) if assoc_seq[x]]