OFFSET

1,3

COMMENTS

Sequence consists of the numbers in which, for each j in 1..N (where N is the number of digits), j is the j-th digit, or is the k-th digit where k is the j-th digit, or is 0.

Equivalently, numbers that can be obtained from the number 1234..N (where N is the number of digits) by swapping the positions of zero or more pairs of digits and replacing zero or more unswapped digits with 0's. (Leading zeros are not allowed, so the '1' cannot be replaced with a 0.)

The maximum number of digits N is 9.

The last term is 987654321.

From Michael S. Branicky, Sep 26 2021: (Start)

The sequence has 29186 terms with <= 9 digits.

If a(n) is a term, then so is 10*a(n), up to the digit limit.

Terms with a higher number of digits could satisfy the property if d(j) = 0 for j >= 10. (End)

LINKS

Michael S. Branicky, Python program for complete sequence

EXAMPLE

103 is a term, 1 is the 1st digit, 3 is the 3rd digit, and there is no digit 2, so the 2nd digit is 0.

1 2 3

| . |

| . |

1 0 3

2143 is a term, 1 and 2 are the 2nd and 1st digits, respectively, and 3 and 4 are the 4th and 3rd digits, respectively.

1 2 3 4

\ / \ /

X X

/ \ / \

2 1 4 3

146203 is a term, 1 is the 1st digit, 2 and 4 are the 4th and 2nd digits, respectively, 3 and 6 are the 6th and 3rd digits, respectively, and there is no digit 5, so the 5th digit is a 0:

1 2 3 4 5 6

| \ \ / . /

| \ X__ __/

| \ / \ /.

| X X .

| / \ __/ \__

| / X . \

| / / \ . \

1 4 6 2 0 3

.

1 2 3 4 5 6 digit positions

term = 1 4 6 2 0 3

^-----^ 2,4 swapped

^--------^ 3,6 swapped

MATHEMATICA

q[n_] := Module[{d = IntegerDigits[n], nd}, nd = Length[d]; AllTrue[Range[nd], d[[#]] == 0 || (d[[#]] <= nd && d[[d[[#]]]] == # ) &]]; Select[Range[0, 13245], q] (* Amiram Eldar, Sep 26 2021 *)

PROG

(Python) # see links for faster version generating entire sequence

def ok(n):

digs = str(n)

if int(max(digs)) > len(digs): return False

for j, dj in enumerate(digs, start=1):

if dj != '0' and digs[int(dj)-1] != str(j): return False

return True

print(list(filter(ok, range(100001)))) # Michael S. Branicky, Sep 26 2021

CROSSREFS

KEYWORD

nonn,base,fini

AUTHOR

Rodolfo Kurchan, Sep 26 2021

EXTENSIONS

More terms added by Claudio Meller, Sep 26 2021

STATUS

approved