Let's define a self-contained number as a positive integer, whose digits appear in runs of length equal to themselves only. In other words, any decimal digit d (excluding 0) occurs only in runs of length exactly d.
You can choose any of the three methods listed below:
- Given an integer n, output the nth (either 0 or 1-indexed) self-contained number.
- Given an integer n, output the first n self-contained numbers.
- Print the sequence indefinitely.
133322 is a self-contained number because 3 appears in a run of three 3's, 1 is single and 2 occurs in a run of two 2's.
On the other hand, 35553355 isn't, because, although 5 and 3 occur five and three times respectively, they do not form runs of adjacent digits.
44422 is not self-contained, because 4 only occurs three times.
12222333 isn’t either, because 2 appears in a run of four 2's, and it cannot be treated as two separate runs of two 2's.
Not surprisingly, this is OEIS A140057, and its first few terms are:
1, 22, 122, 221, 333, 1221, 1333, 3331, 4444, 13331, 14444, 22122, 22333, 33322, 44441, 55555, 122122, 122333, 133322, 144441, 155555
You can take input and provide output through any of the standard methods, in any programming language, while noting that these loopholes are forbidden by default. This is code golf, so the shortest code in bytes (in every language) wins.