f=lambda n,i=0,j=1:j>n and i-1or f(n,i+1,j+(`i`!=`i`[::-1])) for i in [1,5,12]: print('%2s -> %s'%(i,f(i)))
Standard input is empty
1 -> 10 5 -> 15 12 -> 23
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!