Create an unlimited counterstring

Haskell, 60 58 bytes

As a function we get:

f=length.show
iterate(\n->1+n+(f$n+1+f n))2>>=(++"*").show

Full program, 72 70 bytes

This outputs an infinite counterstring to STDOUT:

f=length.show
main=putStr$iterate(\n->1+n+(f$n+1+f n))2>>=(++"*").show

Inputting the length requires 20 additional bytes:

main=interact(\j->take(read j)$iterate(\n->1+n+(f$n+1+f n))2>>=(++"*").show)

This works up to your approximately your RAM size, since Haskell defaults numeric integral types to Integer.


Pyth, 25 17 15 14 bytes

<uu++GlN\*k)Qk

Try it online.

Length is taken via STDIN.


Python 3, 126 114 99 bytes

def f(x,s=''):
 i=t=2
 while len(s)<x:i+=len(str(t+i))-len(str(t));s+=str(t)+'*';t+=i
 print(s[:x])

A function that takes input via argument of the character count at which to truncate the string, and prints to STDOUT.

How it works

The difference between the numbers in the string is initially 2. Every time an order of magnitude is passed, this difference is increased by 1; this can be achieved by taking the difference between the number of digits of the current number and the number of digits of the current number added to the difference, which is 1 only when required. The function simply loops while the length of the string is less than the input, appends to the string and updates the difference and number as required, and then truncates before printing.

Try it on Ideone

Infinite output version, 69 bytes

s=i=2
while 1:i+=len(str(s+i))-len(str(s));print(end=str(s)+'*');s+=i