login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A346036 Number of swaps needed to return the recursive transform T(k) = concatenate(reverse(k), len(k) + 1) to the tuple 1, 2, ..., n. 0
0, 0, 1, 2, 2, 4, 5, 4, 6, 8, 7, 10, 10, 10, 13, 12, 12, 14, 17, 16, 18, 18, 17, 22, 22, 20, 25, 24, 24, 28, 29, 24, 26, 32, 31, 34, 32, 32, 35, 38, 36, 40, 35, 40, 40, 40, 39, 44, 46, 42, 49, 50, 44, 52, 51, 52, 52, 54, 51, 54, 58, 56, 59, 54, 54, 64, 61, 60 (list; graph; refs; listen; history; text; internal format)
OFFSET

1,4

LINKS

Table of n, a(n) for n=1..68.

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

Cf. A220073.

Sequence in context: A214793 A199088 A293974 * A138557 A129303 A255368

Adjacent sequences:  A346033 A346034 A346035 * A346037 A346038 A346039

KEYWORD

nonn

AUTHOR

Emanuel Landeholm, Jul 02 2021

STATUS

approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified October 1 04:05 EDT 2022. Contains 357134 sequences. (Running on oeis4.)