fork download
  1. f=lambda s,c=0:s[1:]and f(min(s).join(`eval(s)`),c+1)or(s,c)
  2.  
  3. for s in '81+31', '351+14568', '21*111', '136*2356':
  4. print '%-9s --> %s' % (s, f(s))
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
81+31     --> ('4', 2)
351+14568 --> ('6', 3)
21*111    --> ('8', 3)
136*2356  --> ('0', 2)