How to generalize the Thue-Morse sequence to more than two symbols?

It's $0, 012, 012 120 201, 012 120 201 120 201 012 201 012 120, ...$

To easily construct the Thue-Morse sequence, you can do the following:

Start with $0$; Replace $(0\to01)$ and $(1\to10)$. So you get: $$0, 0 1, 01 10, 0110 1001, 01101001 10010110,...$$

To easily construct the ternary version of Thue-Morse sequence, you can do the following:

Start with $0$; Replace $(0\to012), (1\to120), (2\to201).$ So you get: $$0, 0 1 2, 012 120 201, 012120201 120201012 201012120$$

To easily construct the $4$-ary version of Thue-Morse sequence, you can do the following:

Start with $0$; Replace $(0\to 0123), (1\to 1230), (2\to2301), (3\to3012).$ So you get: $$0, 0 1 2 3, 0123 1230 2301 3012, 0123123023013012 1230230130120123 2301301201231230 3012012312302301$$

To easily construct the $n$-ary version of Thue-Morse sequence, you can do the following:

Start with $0$; Replace

$$(0\to012\cdots[n-2][n-1]n), (1\to123\cdots[n-1]n0),$$

$$(2\to234\cdots n01),$$

$$\dots$$

$$(n\to n01\cdots[n-3][n-2][n-1]).$$


To find out a particular number n for b symbols, convert the number to base b, sum the digits, and then modulo by b.

For example, you have two symbols, 0 and 1, and you want to find out what the fifteenth place in this sequence would be. Convert 14 (14 is the fifteenth number since this sequence starts with 0) to base two (the number of symbols), it's 1110. Sum the digits, it's 3. Take 3 modulo two (again, the number of symbols). It's 1. So the fifteenth place in the binary Thue-Morse sequence is 1.

If you have four symbols, 0 and 1 and 2 and 3, and you want to find out the twelfth place in the sequence. Convert 11 to base four, it's 23. Sum the digits, it's 5. Five modulo four is 1, so the twelfth place in the quaternary Thue-Morse sequence is also 1.





That was my own discovery back in 2016.

I knew about

T(2n) = T(n)
T(2n+1) = not T(n)

I saw that

T(2n+1) = not T(n) = (T(n)+1) modulo 2.

and thought that one possible generalization for other numbers of symbols could be:

T(bn) = T(n)
T(bn+y) = (T(n)+y) modulo b

where y is lower than b.

Here is a shellscript that prints 0 to $1 iterations where $p is the amount of symbols.

#!/bin/sh
p=6
for i in `seq 0 $1`
do
    echo -n "$(echo "${p}o${i}f"|dc|sed 's/\(.\)/\1 /g')  [+lbx]sa[2z>a]dsbx${p}%n"|dc
done
echo