62 lines
1.5 KiB
Text
62 lines
1.5 KiB
Text
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
|