
# increasing.py

'''
  Challenging Programming in Python
  Habib Izadkhah, Rashid Behzadidoost
  Springer, 2024
  Code 4.3

  Num string 		Expected output
  '457990' 			[4, 5, 7, 9, 90]
  '1' 				[1]
  '13900456' 		[1, 3, 9, 45]
  '27811700' 		[2, 7, 8, 11, 70]
'''


def increasing(numString):
  digits = []
  for ch in numString:
    digits.append(int(ch))

  incrNums = [digits[0]]
  prevNum = digits[0]
  digits = digits[1:]
  numStr = ''
  isSingle = True

  for digit in digits:
    ''' extract the increasing numbers
        that are single digits such as 2,3,4
    '''
    if digit > prevNum and isSingle:
      incrNums.append(digit)
      prevNum = digit
    else:
      ''' extract the increasing numbers
          that have more than one digit
      '''
      isSingle = False
      numStr += str(digit)
      if int(numStr) > prevNum:
        incrNums.append( int(numStr) )
        prevNum = int(numStr)
        numStr = ''
  return incrNums


# ------ main ----------
print('457990', increasing('457990'))
print('27811700', increasing('27811700'))
