def genNDigitPalindrome(n, base=10):
  """
  Generate all n-digit palendromes in requested base, in sequential order
  """
  def _incrementPalinVec(palinVec, base):
    # Increment a list of digits that encodes a palindrome number
    n = 0
    palinVec[n] += 1
    while palinVec[n] == base:
      palinVec[n] = 0
      n += 1
      if n == len(palinVec):
        return False
      palinVec[n] += 1
    return True
  
  def _palinVecToEven(palinVec, base):
    # Convert list of digits to palindrome number with even number of digits
    num = palinVec[-1]
    mult = base
    for d in reversed(palinVec[:-1]):
      num += d * mult
      mult *= base
    for d in palinVec:
      num += d * mult
      mult *= base
    return num
  
  def _palinVecToOdd(palinVec, base):
    # Convert list of digits to palindrome number with odd number of digits
    num = palinVec[-1]
    mult = base
    for d in reversed(palinVec[:-1]):
      num += d * mult
      mult *= base
    for d in palinVec[1:]:
      num += d * mult
      mult *= base
    return num

  if n == 1:
    for n in range(base):
      yield n
  elif n % 2:
    # generate a palindrome with 2 * nHalf + 1 digits
    palinVec = [0] * (n / 2) + [1]
    yield _palinVecToOdd(palinVec, base)
    while _incrementPalinVec(palinVec, base):
      yield _palinVecToOdd(palinVec, base)
  else:
    # generate a palindrome with 2 * nHalf digits
    palinVec = [0] * (n / 2 - 1) + [1]
    yield _palinVecToEven(palinVec, base)
    while _incrementPalinVec(palinVec, base):
      yield _palinVecToEven(palinVec, base)