fork download
  1. g=lambda x,o,i=1:x<10and[x,i]or g(eval(o.join(`x`)),o,i+1)
  2. f=lambda a,o,b:g(eval('%s'*3%(a,o,b)),o)
  3.  
  4. for x in [[81, '+', 31],
  5. [351, '+', 14568],
  6. [21, '*', 111],
  7. [136, '*', 2356]]:
  8. print('%-17s -> %s'%(x,f(*x)))
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]