sed, 116 9292 83 bytes
:l
/^9*$/s/^/0/
s/.9*$/_&/
h
s/.*\([^9]9*\)$*_/\1/
y/0123456789/1234567890/
x
s/[^9]9*$_.*//
G
s/\n//
p
b l
Usage: Sed operates on text input and it needs input do anything. To run the script, feed it with just one empty line:
$ echo | sed -f forever.sed
Explanation:
To increment a number, the current number is split up into a prefix and a suffix where the suffix is of the form [^9]9*
. Each digit in the suffix is then incremented individually, and the two parts are glued back together. If the current number consists of 9
digits only, a 0
digit is appended, which will immediately incremented to a 1
.