A360968 Permutation of the positive integers derived through a process of self-reference and self-editing. a(1) = 1. Other terms generated as described in Comments.
1, 3, 2, 7, 4, 13, 5, 12, 22, 15, 23, 8, 6, 36, 10, 31, 40, 26, 25, 56, 16, 9, 11, 55, 19, 18, 67, 54, 28, 86, 21, 48, 42, 45, 90, 14, 20, 37, 106, 17, 95, 33, 71, 130, 34, 27, 41, 32, 91, 47, 141, 66, 73, 29, 24, 38, 94, 164, 76, 155, 57, 133, 193, 98, 92
Offset: 1
Examples
When n = 2, p = 1, so q := n+a(p) = 2+a(1) = 2+1 = 3. a(3) is "unedited" so a(n) = q and a(q) = n, i.e., set a(2) = 3 and a(3) = 2. Since a(3) was edited by this, we continue at a(4), increasing p to 2. Now, q := n+a(p) = 4+a(2) = 4+3 = 7. a(7) is unedited, so apply a(n) = q and a(q) = n again. i.e., set a(4) = 7 and a(7) = 4 a(5) was not edited previously, so we continue there, increasing p to 3. Next, q := n+a(p) = 5 + a(3) = 5 + 2 = 7. a(7) is a previously edited term, so rather than use a(7)'s nominal value of 7, we instead use its currently held value of 4. I.e., a(n) = a(q) and, as always, a(q) = n. Thus we set a(5) = 4 and a(7) = 5. This must be done in the right order, lest both a(n) and a(q) be set to the same value (5 in this case). At this point, note that while 2 and 3 are swapped relative to the positive integers, 4, 5, and 7 form a 3-cycle through their respective indices. Continuing: a(6) is not yet edited, so n := 6 and p increases to 4. a(p) = 7, so we look to a(6+7) = a(13), an unedited term, so set a(6) = 13 and a(13) = 6, etc. It so happens that a(13) is not edited again and remains 6, but in general it is theoretically possible that an edited term a(k) may be re-edited as long as n < k.
Links
Programs
-
Python
def A360968_list(maxn): B,C,p,n = [1],[],1,1 while n < maxn: for i in range(2*n): B.append(0) n = B.index(0)+1 q = n + B[p-1] if B[q-1] < 1: B[n-1] = q else: B[n-1] = B[q-1] B[q-1] = n p += 1 for i in range(0,len(B)): if B[i]>0 and i+1 <= maxn: C.append(B[i]) return C # John Tyler Rascoe, Mar 04 2023
Comments