I think there is also possibility of 0-0 then total is 4 possibilities.If scores are possible: 1-0, 1-1, 0-1
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
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.
ah sorry, something went wrong with copy/paste. Of course 6 in this case. Thanks. Indeed i had to look after permutations.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.
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).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
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).
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).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.
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
But what algorithm i use
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")
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.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
I want to make something for the upcoming football world cup.
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.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
Actually, I have no idea if such an app already exists. How do those sports journalists do it?
some of the prediction tipsters have quite good blogs about their algorithms and tweaking.
Now I think about it, there is a site here that ranks AFL predictions
Still hunting for the machine-prediction tipping summary.
if you are talking about Football then it is unrealistic to have such amount.think about adding some extra memory to your computer first.
Thanks for the interesting links. Nice to see. And thanks for the algorithm for my app.This one: https: www.squiggle.com.au
View attachment 132980
The prediction leaderboard is here: www.squiggle.com.au/leaderboard
View attachment 132979
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.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 idea is to calculate all possible scores for 3, 4, 5 and 6 teams, and save this as a text file.
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)
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
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 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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
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?