A positive integer $n$ is defined to be evil if the number of ones in its binary expansion is even, otherwise it is odious. Now define the function $$ \begin{equation*} t(n)= \begin{cases} 1 \rm{ \ if \ n \ is \ evil, } \\ 0 \rm{ \ if \ n \ is \ odious. } \\ \end{cases} \end{equation*} $$ The sequence associated with the function $t(n)$ is often referred to as the Thue-Morse sequence.
What is the best/most efficient way to write the function $t(n)$ in Mathematica?
ThueMorseis a built-in function? Is there some reason why you need to define your own version? Like is this homework? – m_goldberg Mar 10 '19 at 22:32FindSequenceFunction, Mathematica will tell you about the built-inThueMorsefunction.FindSequenceFunction[{#, OddQ@Total@IntegerDigits[#, 2] /. {True -> 1, False -> 0}} & /@ Range[0, 10], n]evaluates to
– Bob Hanlon Mar 11 '19 at 14:29ThueMorse[n]