OFFSET
1,2
EXAMPLE
Initially the sequence {b[n]} is {1,2,3,4,5,...};
on the first pass, exchange b(2) with b(b(2) + b(1)) to give {1,3,2,4,5,...};
on the second pass, exchange b(3) with b(b(3) + b(2)), that is, exchange b(3) with b(5) to give {1,3,5,4,2,...}.
MATHEMATICA
For[n = 0, n <= 1000, n++, a[n] = n];
iend = 48;
For[k = 2, k <= iend, k++, t = Table[a[n], {n, 1, iend}]; Print[k, t];
temp = a[k]; index = a[a[k] + a[k - 1]]; a[k] = index;
a[index] = temp];
(* Second program: *)
With[{nn = 67}, Take[#, nn] &@ Fold[ReplacePart[#1, {#2 + 1 -> #1[[Total@ #1[[#2 ;; #2 + 1]] ]], #1[[Total@ #1[[#2 ;; #2 + 1]] ]] -> #1[[#2 + 1]] } ] &, Range[nn^2], Range@ nn] ] (* Michael De Vlieger, Dec 20 2017 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
David S. Newman, Dec 19 2017
STATUS
approved