Perhaps a good direction to take your study is into palandromic numbers such as 11,22,33... then 111, 121, 131, ... then 1221, 1331, 1441 and so on. I did wrtie a small fortran routine years ago. but may work better under the control of string manipulation than arithetic.