dc, 13 characters
Thanks to
- Daemon for reusing stack depth instead of getting it again, to use shorter operator (-1 character)
[zpdA0>x]dsxx
dc, 14 characters
Thanks to
- Digital Trauma for the twist in using the stack depth efficiently (-2 characters)
[zpzA0!<m]dsmx
dc, 16 characters
0[pz+dA0>i]dsixp
Sample run:
bash-5.0$ dc -e '0[pz+dA0>i]dsixp' | head
0
1
2
3
4
5
6
7
8
9