OFFSET
1,2
COMMENTS
Start with all terms set to the nominal value a(n) = n.
Mark all a(n), n > 1 as "unedited", and set a pointer p = 1.
For each unedited a(n), in increasing order of n, let q = n + a(p). Look at a(q). If a(q) has previously been edited, set a(n) = a(q); otherwise, set a(n) = q. In either case, then set a(q) = n. Mark both a(n) and a(q) as "edited". Increase p by 1 and move to the next unedited a(n), etc.
Note that once the process reaches any particular unedited n, sequence terms a(1) to a(n-1) will not be edited further by the generation process and are thus fixed. Terms of the sequence for entries greater than n may have been edited, but are "in flux" and may change again until n reaches them. p necessarily lags behind n, and so any a(p) is always well fixed by the time it is needed.
In many cases the generation process merely swaps two values relative to the positive integers, but since some edited terms could be re-edited, this will cause cycles to occur.
The positions of integers in this sequence would appear to be very hard to predict without actually generating the sequence.
LINKS
EXAMPLE
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.
PROG
(bc) a[p=1]=1; for(n=2; p<=65; p++){while(a[n]).=n++; q=a[p]+n; if(a[q]){a[n]=a[q]}else{a[n]=q}; a[q]=n; print a[p], ", "}; print "\n"
(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
CROSSREFS
KEYWORD
AUTHOR
Carl R. White, Feb 27 2023
STATUS
approved
