Raw Input Desired Output
12399
4579
999
47
12400
4580
1000
48
Script and Comments
Script1
[ 1] s/.9*$/\n&/
[ 2] h
[ 3] y/0123456789/1234567890/
[ 4] G
[ 5] s/.*\n\(.*\)\n\(.*\)\n.*/\2\1/
[ 6] s/^0/10/
Comments
  1. An integer can be splitted into two parts:
    • Part B: consists of digits that will by changed by the increment operation
    • Part A: consists of other digits
    For example:
    NumberAB
    1239912399
    45794579
    999 999
    4747
  2. Step [1] will split a number into two parts and add a newline character between them.
  3. Step [2]: command 'h' will copy the contents of Pattern Space to Hold Space.
  4. Step [3] is used to simulate 'increment by 1': replace 0 with 1, 1 with 2, ..., and 9 with 0.
  5. Step [4]: command 'G' will append the original copy (saved by Step [2]) at the end of Pattern Space, separated by a newline character.
  6. Now PS contains: A' \n B' \n A \n B. where A' and B' are transformed from A and B, respectively, by Step [3]. Only B' is useful.
  7. Step [5] will make PS be A B'.
  8. Step [6] will prepend '1' if PS begins with '0'.