Task

Create a Thue-Morse sequence.



See also
   YouTube entry: The Fairest Sharing Sequence Ever
   YouTube entry: Math and OCD - My story with the Thue-Morse sequence
   Task: Fairshare between two and more


 
Dim As String tm = "0"
 
Function Thue_Morse(s As String) As String
    Dim As String k = ""
    For i As Integer = 1 To Len(s)
        If Mid(s, i, 1) = "1" Then 
            k += "0" 
        Else 
            k += "1"
        End If
    Next i
    Thue_Morse = s + k
End Function
 
Print tm
For j As Integer = 1 To 7
    tm = Thue_Morse(tm)
    Print tm
Next j
End
 