desired algorithm

yeroen

Member
Licensed User
Longtime User
My math knowledge (high school) has gone way down.
I'm looking for a nice algorithm:
<
Four teams in a group all play against each other once.
If scores are possible: 1-0, 1-1, 0-1
How do I get all possible results in an array.
>
For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-1
---
And so on.
 

aeric

Expert
Licensed User
Longtime User
If scores are possible: 1-0, 1-1, 0-1
I think there is also possibility of 0-0 then total is 4 possibilities.

How about other scores like 2-1, 3-0, 7-11, etc ?

Use array or list then use For or While loops.

Something like:
B4X:
Private teams() As String = Array As String("teamA", "teamB", "teamC", "teamD")
Private results() As String = Array As String("0-0", "0-1", "1-0", "1-1")
Log("------------------------------------------------------------")
For i = 0 To teams.Length - 1
    For j = i + 1 To teams.Length - 1            
        For Each result In results
            Log("Teams: " & teams(i) & "-" & teams(j) & " -> " & result)
        Next
        Log("------------------------------------------------------------")
    Next
Next
 

emexes

Expert
Licensed User
Four teams in a group all play against each other once.
If scores are possible: 1-0, 1-1, 0-1
How do I get all possible results in an array.

If each team plays each other team once, shouldn't there be 6 games per group eg:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-1
---
And so on.


rather than the 4 shown in your example:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-1
---
And so on.


and thus we'd be expecting 3 ^ 6 = 729 groups each containing a different permutation of 6 game results.
 

yeroen

Member
Licensed User
Longtime User
If each team plays each other team once, shouldn't there be 6 games per group eg:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-1
---
And so on.


rather than the 4 shown in your example:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-1
---
And so on.


and thus we'd be expecting 3 ^ 6 = 729 groups each containing a different permutation of 6 game results.
ah sorry, something went wrong with copy/paste. Of course 6 in this case. Thanks. Indeed i had to look after permutations.
 

yeroen

Member
Licensed User
Longtime User
I think there is also possibility of 0-0 then total is 4 possibilities.

How about other scores like 2-1, 3-0, 7-11, etc ?

Use array or list then use For or While loops.

Something like:
B4X:
Private teams() As String = Array As String("teamA", "teamB", "teamC", "teamD")
Private results() As String = Array As String("0-0", "0-1", "1-0", "1-1")
Log("------------------------------------------------------------")
For i = 0 To teams.Length - 1
    For j = i + 1 To teams.Length - 1          
        For Each result In results
            Log("Teams: " & teams(i) & "-" & teams(j) & " -> " & result)
        Next
        Log("------------------------------------------------------------")
    Next
Next

I think there is also possibility of 0-0 then total is 4 possibilities.

How about other scores like 2-1, 3-0, 7-11, etc ?

Use array or list then use For or While loops.

Something like:
B4X:
Private teams() As String = Array As String("teamA", "teamB", "teamC", "teamD")
Private results() As String = Array As String("0-0", "0-1", "1-0", "1-1")
Log("------------------------------------------------------------")
For i = 0 To teams.Length - 1
    For j = i + 1 To teams.Length - 1           
        For Each result In results
            Log("Teams: " & teams(i) & "-" & teams(j) & " -> " & result)
        Next
        Log("------------------------------------------------------------")
    Next
Next
Thank you. It's elegant but not exactly what I meant. There are 6 matches possible and 729 groups with different results in each group (see emexes' reaction). How do I get all these groups into a list? As far as the results are concerned, I only care about a win (1-0), a draw (1-1) and a loss (0-1).
 

yeroen

Member
Licensed User
Longtime User
If each team plays each other team once, shouldn't there be 6 games per group eg:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-1
---
And so on.


rather than the 4 shown in your example:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-1
---
And so on.


and thus we'd be expecting 3 ^ 6 = 729 groups each containing a different permutation of 6 game resultsI get all these groups into a list? As far as the results are concerned, I only care about a win (1-0), a draw (1-1) and a loss (0-1).

If each team plays each other team once, shouldn't there be 6 games per group eg:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamC 1-0
teamB-teamD 1-0
teamC-teamD 1-1
---
And so on.


rather than the 4 shown in your example:

For example:
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-0
---
teamA-teamB 1-0
teamA-teamC 1-0
teamA-teamD 1-0
teamB-teamD 1-1
---
And so on.


and thus we'd be expecting 3 ^ 6 = 729 groups each containing a different permutation of 6 game results.
But what algorithm i use to get all these groups into a list or array (each item is a group)? As far as the results are concerned, I only care about a win (1-0), a draw (1-1) and a loss (0-1).
 

William Lancee

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Log(TAB & TAB & "AB" & TAB & "AC" & TAB & "AD" & TAB & "BC" & TAB & "BD" & TAB & "CD")
    Dim v() As String = Array As String("1:0", "1:1", "0:1")
    For k = 0 To 728
        Dim sb As StringBuilder: sb.Initialize
        For Each number As Int In toBaseN(k, 3, 6)
            sb.append(v(number)).Append(TAB)
        Next
        Log(k & TAB & TAB & sb.ToString)
    Next
End Sub


Private Sub toBaseN(number As Int, base As Int, ngrps As Int) As List
    Dim result As List: result.Initialize
    Do While number > 0
        Dim mult As Int = Floor(number / base)
        Dim remainder As Int = number Mod base
        result.Add(remainder)
        number = mult
    Loop
    For j = result.Size To ngrps - 1
        result.Add(0)
    Next
    Return result
End Sub
 

emexes

Expert
Licensed User
But what algorithm i use

If the number of teams is fixed at 4, and thus the games per group is fixed at 6, then it's easiest just to have 6 nested For..Next loops eg:

B4X:
Dim TeamName() As String  = Array As String("TeamA", "TeamB", "TeamC", "TeamD")
Dim WinDrawLoss() As String = Array As String("1-0", "1-1", "0-1")

Dim SeasonNumber As Int = 0

For ResultAB = 0 To 2
	For ResultAC = 0 To 2
		For ResultAD = 0 To 2
			For ResultBC = 0 To 2
				For ResultBD = 0 To 2
					For ResultCD = 0 To 2
						SeasonNumber = SeasonNumber + 1
						Log("--- season " & SeasonNumber)
						Log(TeamName(0) & "-" & TeamName(1) & " " & WinDrawLoss(ResultAB))
						Log(TeamName(0) & "-" & TeamName(2) & " " & WinDrawLoss(ResultAC))
						Log(TeamName(0) & "-" & TeamName(3) & " " & WinDrawLoss(ResultAD))
						Log(TeamName(1) & "-" & TeamName(2) & " " & WinDrawLoss(ResultBC))
						Log(TeamName(1) & "-" & TeamName(3) & " " & WinDrawLoss(ResultBD))
						Log(TeamName(2) & "-" & TeamName(3) & " " & WinDrawLoss(ResultCD))
					Next
				Next
			Next
		Next
	Next
Next
Log("--- finito")

Log output:
Waiting for debugger to connect...
Program started.
--- season 1
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-0
TeamC-TeamD 1-0
--- season 2
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-0
TeamC-TeamD 1-1
--- season 3
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-0
TeamC-TeamD 0-1
--- season 4
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-1
TeamC-TeamD 1-0
--- season 5
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-1
TeamC-TeamD 1-1
--- season 6
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-1
TeamC-TeamD 0-1
--- season 7
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 0-1
TeamC-TeamD 1-0
--- season 8
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 0-1
TeamC-TeamD 1-1
--- season 9
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 0-1
TeamC-TeamD 0-1
--- season 10
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-1
TeamB-TeamD 1-0
TeamC-TeamD 1-0
--- season 11

[and so on]

--- season 726
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 1-1
TeamC-TeamD 0-1
--- season 727
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 0-1
TeamC-TeamD 1-0
--- season 728
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 0-1
TeamC-TeamD 1-1
--- season 729
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 0-1
TeamC-TeamD 0-1
--- finito
 
Last edited:

yeroen

Member
Licensed User
Longtime User
If the number of teams is fixed at 4, and thus the games per group is fixed at 6, then it's easiest just to have 6 nested For..Next loops eg:

B4X:
Dim TeamName() As String  = Array As String("TeamA", "TeamB", "TeamC", "TeamD")
Dim WinDrawLoss() As String = Array As String("1-0", "1-1", "0-1")

Dim SeasonNumber As Int = 0

For ResultAB = 0 To 2
    For ResultAC = 0 To 2
        For ResultAD = 0 To 2
            For ResultBC = 0 To 2
                For ResultBD = 0 To 2
                    For ResultCD = 0 To 2
                        SeasonNumber = SeasonNumber + 1
                        Log("--- season " & SeasonNumber)
                        Log(TeamName(0) & "-" & TeamName(1) & " " & WinDrawLoss(ResultAB))
                        Log(TeamName(0) & "-" & TeamName(2) & " " & WinDrawLoss(ResultAC))
                        Log(TeamName(0) & "-" & TeamName(3) & " " & WinDrawLoss(ResultAD))
                        Log(TeamName(1) & "-" & TeamName(2) & " " & WinDrawLoss(ResultBC))
                        Log(TeamName(1) & "-" & TeamName(3) & " " & WinDrawLoss(ResultBD))
                        Log(TeamName(2) & "-" & TeamName(3) & " " & WinDrawLoss(ResultCD))
                    Next
                Next
            Next
        Next
    Next
Next
Log("--- finito")

Log output:
Waiting for debugger to connect...
Program started.
--- season 1
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-0
TeamC-TeamD 1-0
--- season 2
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-0
TeamC-TeamD 1-1
--- season 3
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-0
TeamC-TeamD 0-1
--- season 4
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-1
TeamC-TeamD 1-0
--- season 5
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-1
TeamC-TeamD 1-1
--- season 6
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 1-1
TeamC-TeamD 0-1
--- season 7
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 0-1
TeamC-TeamD 1-0
--- season 8
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 0-1
TeamC-TeamD 1-1
--- season 9
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-0
TeamB-TeamD 0-1
TeamC-TeamD 0-1
--- season 10
TeamA-TeamB 1-0
TeamA-TeamC 1-0
TeamA-TeamD 1-0
TeamB-TeamC 1-1
TeamB-TeamD 1-0
TeamC-TeamD 1-0
--- season 11

[and so on]

--- season 726
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 1-1
TeamC-TeamD 0-1
--- season 727
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 0-1
TeamC-TeamD 1-0
--- season 728
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 0-1
TeamC-TeamD 1-1
--- season 729
TeamA-TeamB 0-1
TeamA-TeamC 0-1
TeamA-TeamD 0-1
TeamB-TeamC 0-1
TeamB-TeamD 0-1
TeamC-TeamD 0-1
--- finito
woooow looks so good. I will look after it.
Anyway, thanks community for the tips. I want to make something for the upcoming football world cup. Purely as a hobby and to pick up programming (in B4X) again.
If you have the time and inclination, see attachment for B4J.
 

Attachments

  • FootballPredictionWindowsB4J.zip
    80.2 KB · Views: 106

emexes

Expert
Licensed User
I want to make something for the upcoming football world cup.

If you're going to increase the number of teams to more than 6, then you might want to think about adding some extra memory to your computer first. šŸ»

1661382098602.png
 

yeroen

Member
Licensed User
Longtime User
If you're going to increase the number of teams to more than 6, then you might want to think about adding some extra memory to your computer first. šŸ»

View attachment 132977
What a beautiful matrix. Yes, I was already worried about those memory problems. Most tournaments consist of 4 teams per group. But for example for the qualification for a tournament it is per continent and then there can be 10 teams in a group.
I have to limit that. Or build in something that only concerns the first 4 teams.
Actually, I have no idea if such an app already exists. How do those sports journalists do it?
 

emexes

Expert
Licensed User
Actually, I have no idea if such an app already exists. How do those sports journalists do it?

A lot of sport prediction methods begin with this:

https://en.wikipedia.org/wiki/Elo_rating_system

and then add in things like home-ground advantage, weather, how bad the team needs to win (to stay in the competition).

Now I think about it, there is a site here that ranks AFL predictions, and some of the prediction tipsters have quite good blogs about their algorithms and tweaking. Hang on a sec while I hunt that down...
 

DonManfred

Expert
Licensed User
Longtime User
think about adding some extra memory to your computer first. šŸ»
if you are talking about Football then it is unrealistic to have such amount.

Usually a team has TWO games per season within a league. Even with 18 Teams there are only a few hundred games needed per season.
 

yeroen

Member
Licensed User
Longtime User
Thanks for the interesting links. Nice to see. And thanks for the algorithm for my app.
My idea is to calculate all possible scores for 3, 4, 5 and 6 teams, and save this as a text file. Depending on the situation, the app then opens the correct text file and uses this data instead of calculating it.
Also in response to other comments: My app only concerns tournaments and not an entire season. A tournament (such as FIFA WC Qatar 2022) usually involves about 8 groups with 4 teams in each group. There is therefore only once played against each other (no home and away matches). And this is manageable.
In my app, the user can research what it takes for a particular team to finish 1st or 2nd (usually 1st and 2nd advance to the finals). I only use win, draw or lose. If teams are tied, I will suffice with the statement that the goal difference is decisive.
All in all, this is the best way to master programming (in B4X). I still have a lot of old habits to unlearn.
 

yeroen

Member
Licensed User
Longtime User
if you are talking about Football then it is unrealistic to have such amount.

Usually a team has TWO games per season within a league. Even with 18 Teams there are only a few hundred games needed per season.
My app only concerns tournaments and not an entire season. A tournament (such as FIFA WC Qatar 2022) usually involves about 8 groups with 4 teams in each group. There is therefore only once played against each other (no home and away matches). And this is manageable.
In my app, the user can research what it takes for a particular team to finish 1st or 2nd (usually 1st and 2nd advance to the finals). I only use win, draw or lose. If teams are tied, I will suffice with the statement that the goal difference is decisive.
 

emexes

Expert
Licensed User
My idea is to calculate all possible scores for 3, 4, 5 and 6 teams, and save this as a text file.

Here's an algorithm where you can set the number of teams:

B4X:
Dim NumTeams As Int = 3    '2..5 or maybe 6 if you don't mind waiting
Dim NumTournamentGames As Int = NumTeams * (NumTeams - 1) / 2

Dim sb As StringBuilder

'*** TOURNAMENT GAMES HEADING LINE ***
sb.Initialize
For T1 = 1 To NumTeams
    For T2 = T1 + 1 To NumTeams
        sb.Append(TAB & Chr(64 + T1) & Chr(64 + T2))    'teams are named A, B, C, etc (ASCII 65, 66, 67, etc)
    Next
Next
Log(TAB & sb.ToString)

Dim WinDrawLoss() As String = Array As String("1-0", "1-1", "0-1")

Dim GameResult(NumTournamentGames) As Int    'start at all zero
Dim NumTournamentOutcomes As Int = 0

Dim DoneFlag As Boolean = False
Do Until DoneFlag
    NumTournamentOutcomes = NumTournamentOutcomes + 1

    '*** TOURNAMENT GAME RESULTS ***
    sb.Initialize
    For G = 0 To NumTournamentGames - 1
        sb.Append(TAB & WinDrawLoss(GameResult(G)))
    Next
    Log(NumTournamentOutcomes & TAB & sb.ToString)
 
    '*** INCREMENT TO NEXT TOURNAMENT OUTCOME ***
    DoneFlag = True    'set false if increments without wraparound back to all zero
    For G = 0 To NumTournamentGames - 1
        If GameResult(G) < 2 Then
            GameResult(G) = GameResult(G) + 1
            DoneFlag = False
            Exit
        Else
            GameResult(G) = 0
        End If
    Next
Loop

Dim ExpectedNumTournamentOutcomes As Long = Power(3, NumTournamentGames)
Log("Double-check: 3 ^ " & NumTournamentGames & " = " & ExpectedNumTournamentOutcomes)

Log output for 3 teams:
Waiting for debugger to connect...
Program started.
        AB    AC    BC
1        1-0    1-0    1-0
2        1-1    1-0    1-0
3        0-1    1-0    1-0
4        1-0    1-1    1-0
5        1-1    1-1    1-0
6        0-1    1-1    1-0
7        1-0    0-1    1-0
8        1-1    0-1    1-0
9        0-1    0-1    1-0
10        1-0    1-0    1-1
11        1-1    1-0    1-1
12        0-1    1-0    1-1
13        1-0    1-1    1-1
14        1-1    1-1    1-1
15        0-1    1-1    1-1
16        1-0    0-1    1-1
17        1-1    0-1    1-1
18        0-1    0-1    1-1
19        1-0    1-0    0-1
20        1-1    1-0    0-1
21        0-1    1-0    0-1
22        1-0    1-1    0-1
23        1-1    1-1    0-1
24        0-1    1-1    0-1
25        1-0    0-1    0-1
26        1-1    0-1    0-1
27        0-1    0-1    0-1
Double-check: 3 ^ 3 = 27

Log output for 6 teams:
14348876        1-1    1-1    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348877        0-1    1-1    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348878        1-0    0-1    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348879        1-1    0-1    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348880        0-1    0-1    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348881        1-0    1-0    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348882        1-1    1-0    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348883        0-1    1-0    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348884        1-0    1-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348885        1-1    1-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348886        0-1    1-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348887        1-0    0-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348888        1-1    0-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348889        0-1    0-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348890        1-0    1-0    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348891        1-1    1-0    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348892        0-1    1-0    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348893        1-0    1-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348894        1-1    1-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348895        0-1    1-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348896        1-0    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348897        1-1    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348898        0-1    0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348899        1-0    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348900        1-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348901        0-1    1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348902        1-0    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348903        1-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348904        0-1    1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348905        1-0    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348906        1-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
14348907        0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1    0-1
Double-check: 3 ^ 15 = 14348907
 
Last edited:

yeroen

Member
Licensed User
Longtime User
Beautiful. And it works much faster than with the nested loops.
I edited it (see below). I put the results in the arrays TextFieldHomeScore() and TextFieldAwayScore(), this only needs to be done once: when user starts the Predictions component.
After that, it is always used to calculate the prediction of the desired ranking of a desired team, depending on matches already played.
Such a prediction in each group with 4 teams (FIFA WC Qatar 2022), only makes sense if each team has played at least 1 match.
This brings me to DonManfred's reaction: what to do in a long season of home and away matches? Again, a prediction only makes sense if there are still 6 (or 5 or 4 or 3) matches to be played in that season.
You then use the existing ranking in a group and analyze the remaining (so a maximum of 6) matches.
I realize that I still have a lot to adjust in my app.

<
Sub MakePlayList
Private TextFieldHomeScore(1000,31), TextFieldAwayScore(1000,31) As String 'i need to adjust this...

'and thus we'd be expecting 3 ^ 6 = 729 groups each containing a different permutation of 6 game results.

'Dim NumTeams As Int = Main.TotalTeamsPerGroupe(1) 'now it is 4 '2..5 or maybe 6 if you don't mind waiting
'There is a problem if some groupes have more or less teams. Then extra work to do...
Dim NumTeams As Int = 4 '2..5 or maybe 6 if you don't mind waiting
Dim NumTournamentGames As Int = NumTeams * (NumTeams - 1) / 2

Dim sb As StringBuilder

'*** TOURNAMENT GAMES HEADING LINE ***
' sb.Initialize
' For T1 = 1 To NumTeams
' For T2 = T1 + 1 To NumTeams
' sb.Append(TAB & Chr(64 + T1) & Chr(64 + T2)) 'teams are named A, B, C, etc (ASCII 65, 66, 67, etc)
' Next
' Next
' Log(TAB & sb.ToString)

Dim WinDrawLoss() As String = Array As String("1-0", "1-1", "0-1")

Dim GameResult(NumTournamentGames) As Int 'start at all zero
Dim NumTournamentOutcomes As Int = 0

Dim DoneFlag As Boolean = False
Do Until DoneFlag
NumTournamentOutcomes = NumTournamentOutcomes + 1

'*** TOURNAMENT GAME RESULTS ***
sb.Initialize
For G = 0 To NumTournamentGames - 1
'sb.Append(TAB & WinDrawLoss(GameResult(G)))
sb.Append(WinDrawLoss(GameResult(G)))
Next
Log(NumTournamentOutcomes & TAB & sb.ToString)
Dim i As Int=0
Dim GameIndex As Int=0
For i=0 To sb.ToString.Length-1
If sb.ToString.CharAt(i)="-" Then
GameIndex=GameIndex+1
TextFieldHomeScore(NumTournamentOutcomes,GameIndex)=sb.ToString.CharAt(i-1)
TextFieldAwayScore(NumTournamentOutcomes,GameIndex)=sb.ToString.CharAt(i+1)
End If
Next

'*** INCREMENT TO NEXT TOURNAMENT OUTCOME ***
DoneFlag = True 'set false if increments without wraparound back to all zero
For G = 0 To NumTournamentGames - 1
If GameResult(G) < 2 Then
GameResult(G) = GameResult(G) + 1
DoneFlag = False
Exit
Else
GameResult(G) = 0
End If
Next
Loop

Dim ExpectedNumTournamentOutcomes As Long = Power(3, NumTournamentGames)
Log("Double-check: 3 ^ " & NumTournamentGames & " = " & ExpectedNumTournamentOutcomes)
Dim i,j As Int
For i= 1 To NumTournamentOutcomes
Log("all scores "&i)
For j=1 To 6
Log(TextFieldHomeScore(i,j) & TextFieldAwayScore(i,j))
Next
Next

End Sub
>
 
Top