fork download
  1. import re
  2. def checkNum(s):
  3. first = ''
  4. if s == '0':
  5. return True
  6. m = re.match(r'\d+$', s) # The string must be all digits
  7. if m:
  8. lim = ''
  9. for i, n in enumerate(s):
  10. lim = lim + n
  11. if re.match(r'{0}\d{{{0}}}$'.format(lim), s):
  12. return True
  13. elif int(s[0:i+1]) > len(s[i+1:]):
  14. return False
  15.  
  16. print(checkNum('3123')) # Meets the pattern (123 is 3 digit chunk after 3)
  17. print(checkNum('1234567')) # Does not meet the pattern, just 7 digits
  18. print(checkNum('100123456789')) # Meets the condition, 10 is followed with 10 digits
  19. print(checkNum('9123456789')) # Meets the condition, 9 is followed with 9 digits
Success #stdin #stdout 0.01s 9024KB
stdin
Standard input is empty
stdout
True
False
True
True