login
Number of ternary words of length 2n obtained by self-shuffling.
2

%I #33 Jan 03 2021 09:52:24

%S 1,3,15,93,621,4425,32703,248901,1934007,15285771,122437215,991731999,

%T 8107830597

%N Number of ternary words of length 2n obtained by self-shuffling.

%C See A191755 for the number of binary words of length 2n obtained by self-shuffling and also for an explanation of "self-shuffling" and a reference.

%H N. Rampersad and J. Shallit, <a href="http://arxiv.org/abs/1106.5767">Shuffling and unshuffling</a>, preprint, arXiv:1106.5767 [cs.FL], 2011.

%e a(2) = 15 because {0,0,0,0}, {0,0,1,1}, {0,0,2,2}, {0,1,0,1}, {0,2,0,2}, {1,0,1,0}, {1,1,0,0}, {1,1,1,1}, {1,1,2,2}, {1,2,1,2}, {2,0,2,0}, {2,1,2,1}, {2,2,0,0}, {2,2,1,1}, {2,2,2,2} (and no other ternary words of length 4) are generated by self-shuffling.

%o (Python)

%o from itertools import product, combinations

%o def a(n):

%o if n<=1: return 3**n

%o range2n, set2n = list(range(2*n)), set(range(2*n))

%o allset, ssw = set(), [0 for i in range(2*n)]

%o for w in product("012", repeat=n-1):

%o w = "0" + "".join(w)

%o if w.count("1") > w.count("2"): continue

%o for s in combinations(range2n, n):

%o nots = sorted(set2n-set(s))

%o for i, c in enumerate(w): ssw[s[i]] = ssw[nots[i]] = c

%o allset.add("".join(ssw))

%o num2g1 = sum(w.count("1") < w.count("2") for w in allset)

%o return 3*(len(allset) + num2g1)

%o print([a(n) for n in range(8)]) # _Michael S. Branicky_, Jan 03 2021

%Y Cf. A191755.

%K nonn,more

%O 0,2

%A _John W. Layman_, Jun 27 2011

%E a(8)-a(9) from _Alois P. Heinz_, Sep 26 2011

%E a(10)-a(12) from _Bert Dobbelaere_, Oct 02 2018