Skip to content

Instantly share code, notes, and snippets.

@sjorspa
Created October 31, 2023 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjorspa/657f637a92d9d075d849d18974feea5a to your computer and use it in GitHub Desktop.
Save sjorspa/657f637a92d9d075d849d18974feea5a to your computer and use it in GitHub Desktop.
$points = @()
$points += [PsCustomObject]@{team = 'ENG'; q = 0 }
$points += [PsCustomObject]@{team = 'IND'; q = 0 }
$points += [PsCustomObject]@{team = 'NED'; q = 0 }
$points += [PsCustomObject]@{team = 'PAK'; q = 0 }
$points += [PsCustomObject]@{team = 'AUS'; q = 0 }
$points += [PsCustomObject]@{team = 'SA'; q = 0 }
$points += [PsCustomObject]@{team = 'SL'; q = 0 }
$points += [PsCustomObject]@{team = 'BAN'; q = 0 }
$points += [PsCustomObject]@{team = 'NZ'; q = 0 }
$points += [PsCustomObject]@{team = 'AFG'; q = 0 }
$teams = @('IND', 'SA', 'NZ', 'AUS', 'AFG', 'SL', 'PAK', 'NED', 'BAN', 'ENG')
for ($i = 0; $i -lt 10000; $i++) {
<# Action that will repeat until the condition is met #>
$games = @()
$games += [PsCustomObject]@{team1 = 'ENG'; team2 = 'NZ'; winner = 'NZ' }
$games += [PsCustomObject]@{team1 = 'PAK'; team2 = 'NED'; winner = 'PAK' }
$games += [PsCustomObject]@{team1 = 'AFG'; team2 = 'BAN'; winner = 'BAN' }
$games += [PsCustomObject]@{team1 = 'SA'; team2 = 'SL'; winner = 'SA' }
$games += [PsCustomObject]@{team1 = 'AUS'; team2 = 'IND'; winner = 'IND' }
$games += [PsCustomObject]@{team1 = 'NZ'; team2 = 'NED'; winner = 'NZ' }
$games += [PsCustomObject]@{team1 = 'ENG'; team2 = 'BAN'; winner = 'ENG' }
$games += [PsCustomObject]@{team1 = 'SL'; team2 = 'PAK'; winner = 'PAK' }
$games += [PsCustomObject]@{team1 = 'AFG'; team2 = 'IND'; winner = 'IND' }
$games += [PsCustomObject]@{team1 = 'SA'; team2 = 'AUS'; winner = 'SA' }
$games += [PsCustomObject]@{team1 = 'BAN'; team2 = 'NZ'; winner = 'NZ' }
$games += [PsCustomObject]@{team1 = 'PAK'; team2 = 'IND'; winner = 'IND' }
$games += [PsCustomObject]@{team1 = 'AFG'; team2 = 'ENG'; winner = 'AFG' }
$games += [PsCustomObject]@{team1 = 'SL'; team2 = 'AUS'; winner = 'AUS' }
$games += [PsCustomObject]@{team1 = 'NED'; team2 = 'SA'; winner = 'NED' }
$games += [PsCustomObject]@{team1 = 'NZ'; team2 = 'AFG'; winner = 'NZ' }
$games += [PsCustomObject]@{team1 = 'BAN'; team2 = 'IND'; winner = 'IND' }
$games += [PsCustomObject]@{team1 = 'AUS'; team2 = 'PAK'; winner = 'AUS' }
$games += [PsCustomObject]@{team1 = 'NED'; team2 = 'SL'; winner = 'SL' }
$games += [PsCustomObject]@{team1 = 'SA'; team2 = 'ENG'; winner = 'SA' }
$games += [PsCustomObject]@{team1 = 'NZ'; team2 = 'IND'; winner = 'IND' }
$games += [PsCustomObject]@{team1 = 'PAK'; team2 = 'AFG'; winner = 'AFG' }
$games += [PsCustomObject]@{team1 = 'SA'; team2 = 'BAN'; winner = 'SA' }
$games += [PsCustomObject]@{team1 = 'AUS'; team2 = 'NED'; winner = 'AUS' }
$games += [PsCustomObject]@{team1 = 'ENG'; team2 = 'SL'; winner = 'SL' }
$games += [PsCustomObject]@{team1 = 'PAK'; team2 = 'SA'; winner = 'SA' }
$games += [PsCustomObject]@{team1 = 'AUS'; team2 = 'NZ'; winner = 'AUS' }
$games += [PsCustomObject]@{team1 = 'NED'; team2 = 'BAN'; winner = 'NED' }
$games += [PsCustomObject]@{team1 = 'IND'; team2 = 'ENG'; winner = 'IND' }
$games += [PsCustomObject]@{team1 = 'SL'; team2 = 'AFG'; winner = 'AFG' }
$games += [PsCustomObject]@{team1 = 'BAN'; team2 = 'PAK'; winner = 'PAK' }
$games += [PsCustomObject]@{team1 = 'NZ'; team2 = 'SA'; winner = '' }
$games += [PsCustomObject]@{team1 = 'IND'; team2 = 'SL'; winner = '' }
$games += [PsCustomObject]@{team1 = 'NED'; team2 = 'AFG'; winner = '' }
$games += [PsCustomObject]@{team1 = 'NZ'; team2 = 'PAK'; winner = '' }
$games += [PsCustomObject]@{team1 = 'ENG'; team2 = 'AUS'; winner = '' }
$games += [PsCustomObject]@{team1 = 'IND'; team2 = 'SA'; winner = '' }
$games += [PsCustomObject]@{team1 = 'BAN'; team2 = 'SL'; winner = '' }
$games += [PsCustomObject]@{team1 = 'AUS'; team2 = 'AFG'; winner = '' }
$games += [PsCustomObject]@{team1 = 'ENG'; team2 = 'NED'; winner = '' }
$games += [PsCustomObject]@{team1 = 'NZ'; team2 = 'SL'; winner = '' }
$games += [PsCustomObject]@{team1 = 'SA'; team2 = 'AFG'; winner = '' }
$games += [PsCustomObject]@{team1 = 'AUS'; team2 = 'BAN'; winner = '' }
$games += [PsCustomObject]@{team1 = 'ENG'; team2 = 'PAK'; winner = '' }
$games += [PsCustomObject]@{team1 = 'IND'; team2 = 'NED'; winner = '' }
foreach ($game in $games | Where-Object { $_.winner -eq '' }) {
if (Get-Random -InputObject ([bool]$True, [bool]$False)) {
$game.winner = $game.team1
}
else {
$game.winner = $game.team2
}
}
$standings = @()
foreach ($team in $teams) {
$result = ($games | Where-Object { $_.team1 -eq $team -or $_.team2 -eq $team -and $_.winner -eq $team }).Count * 2
$standings += [PsCustomObject]@{team = $team; points = $result }
}
$sortedstanding = $standings | Sort-Object -Property points -Descending
$tiebreakerpoints = $sortedstanding[3].points
$qualifiers = $sortedstanding | Where-Object { $_.points -gt $tiebreakerpoints }
$tiebreakers = $sortedstanding | Where-Object { $_.points -eq $tiebreakerpoints }
$tiebreakplaces = 4 - $qualifiers.Count
$tiebreakpoints = ($tiebreakplaces / $tiebreakers.Count)
foreach ($qualifier in $qualifiers) {
$item = $points | Where-Object { $_.team -eq $qualifier.team }
$item.q = $Item.q + 1
}
foreach ($tiebreaker in $tiebreakers) {
$item = $points | Where-Object { $_.team -eq $tiebreaker.team }
$item.q = $Item.q + $tiebreakpoints
}
}
$points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment