fork download
  1. import strutils
  2.  
  3. proc elem(count:int, ch: char): string =
  4. if count>2: $ch else: $count&ch
  5.  
  6. iterator items(limit: int): string =
  7. var number="0"
  8. for n in 1..limit:
  9. yield number
  10. var count=0
  11. var next=""
  12. for i in 0..<number.len:
  13. if i==0 or number[i-1]==number[i]:
  14. count+=1
  15. else:
  16. next&=elem(count,number[i-1])
  17. count=1
  18. next&=elem(count,number[number.high])
  19. number=next
  20.  
  21. for s in stdin.readLine.parseInt: echo s
Success #stdin #stdout 0s 2440KB
stdin
15
stdout
0
10
1110
110
2110
122110
11222110
2122110
1211222110
11122122110
12211222110
11222122110
21211222110
1211122122110
111212211222110