OFFSET
1,4
EXAMPLE
For n=7, the T transforms give tuple 6,4,2,1,3,5,7 (triangle A220073 row 7) which requires a(7) = 5 swaps to return to 1,2,3,4,5,6,7.
PROG
(Python)
def swaps(l, start = 0):
if len(l) == 0:
return 0
n = start + 1
if l[0] != n:
for i, x in enumerate(l):
if x == n:
l[0], l[i] = l[i], l[0]
return 1 + swaps(l[1:], n)
else:
raise
else:
return swaps(l[1:], n)
def T(l):
n = len(l)
l.reverse()
l.append(n + 1)
return l
if __name__ == "__main__":
l = [ ]
for n in range(1, 100):
l = T(l)
n_swaps = swaps(l[:])
print("{}, ".format(n_swaps), end="")
(PARI) a(n) = my(h=n>>1); n - #permcycles(vectorsmall(n, i, abs(2*i-n) + (i<=h))); \\ Kevin Ryde, Jul 23 2021
CROSSREFS
KEYWORD
nonn
AUTHOR
Emanuel Landeholm, Jul 02 2021
STATUS
approved