The Thue-Morse sequence is a sequence of ones and zeros that if two people
take turns in the given order, the first persons turn for every '0' in the
sequence, the second for every '1'; then this is shown to give a fairer, more
equitable sharing of resources. (Football penalty shoot-outs for example, might
not favour the team that goes first as much if the penalty takers take turns
according to the Thue-Morse sequence and took 2^n penalties)

The Thue-Morse sequence of ones-and-zeroes can be generated by:

"When counting in binary, the digit sum modulo 2 is the Thue-Morse sequence"


Sharing fairly between two or more

Use this method:

When counting base b, the digit sum modulo b is the Thue-Morse sequence of fairer sharing between b people.


Task
Counting from zero;   using a function/method/routine to express an integer count in base b,

sum the digits modulo b to produce the next member of the Thue-Morse fairshare series for b people.



Show the first 25 terms of the fairshare sequence:

   For two people:
   For three people
   For five people
   For eleven people


Related tasks

   Non-decimal radices/Convert
   Thue-Morse


See also

   A010060, A053838, A053840: The On-Line Encyclopedia of Integer Sequences® (OEIS®)


 
Function Turn(mibase As Integer, n As Integer) As Integer
    Dim As Integer sum = 0
    While n <> 0
        Dim As Integer re = n Mod mibase
        n \= mibase
        sum += re
    Wend
    Return sum Mod mibase
End Function
 
Sub Fairshare(mibase As Integer, count As Integer)
    Print Using "mibase ##:"; mibase;
    For i As Integer = 1 To count
        Dim As Integer t = Turn(mibase, i - 1)
        Print Using " ##"; t;
    Next i
    Print
End Sub
 
Sub TurnCount(mibase As Integer, count As Integer)
    Dim As Integer cnt(mibase), i
    For i = 1 To mibase
        cnt(i - 1) = 0
    Next i
 
    For i = 1 To count
        Dim As Integer t = Turn(mibase, i - 1)
        cnt(t) += 1
    Next i
 
    Dim As Integer minTurn = 4294967295 'MaxValue of uLong
    Dim As Integer maxTurn = 0 'MinValue of uLong
    Dim As Integer portion = 0
    For i As Integer = 1 To mibase
        Dim As Integer num = cnt(i - 1)
        If num > 0 Then portion += 1
        If num < minTurn Then minTurn = num
        If num > maxTurn Then maxTurn = num
    Next i
 
    Print Using "  With ##### people: "; mibase;
    If 0 = minTurn Then
        Print Using "Only & have a turn"; portion
    Elseif minTurn = maxTurn Then
        Print minTurn
    Else
        Print Using "& or &"; minTurn; maxTurn
    End If
End Sub
 
Fairshare(2, 25)
Fairshare(3, 25)
Fairshare(5, 25)
Fairshare(11, 25)
 
Print "How many times does each get a turn in 50000 iterations?"
TurnCount(191, 50000)
TurnCount(1377, 50000)
TurnCount(49999, 50000)
TurnCount(50000, 50000)
TurnCount(50001, 50000)
Sleep
 