Created
June 7, 2016 21:02
-
-
Save nolaneo/015f936a4180d6fa8571bd471754d1ab to your computer and use it in GitHub Desktop.
Euro 2016 Pool Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GROUP A | |
# Albania - 401/1 | |
# France - 4.2/1 | |
# Romania 126/1 | |
# Switzerland 51/1 | |
# GROUP B | |
# England 9/1 | |
# Russia 67/1 | |
# Slovakia 151/1 | |
# Wales 81/1 | |
# GROUP C | |
# Germany 5.5/1 | |
# Northern Ireland 301/1 | |
# Poland 51/1 | |
# Ukraine 67/1 | |
# GROUP D | |
# Croatia 26/1 | |
# Czech Republic 126/1 | |
# Spain 5.5/1 | |
# Turkey 67/1 | |
# GROUP E | |
# Belgium 12/1 | |
# Italy 17/1 | |
# Republic of Ireland 101/1 | |
# Sweden 101/1 | |
# GROUP F | |
# Austria 41/1 | |
# Hungary 401/1 | |
# Iceland 151/1 | |
# Portugal 15/1 | |
TIER_1_TEAMS = [ | |
{ team: 'France', group: 'A' }, | |
{ team: 'England', group: 'B' }, | |
{ team: 'Germany', group: 'C' }, | |
{ team: 'Spain', group: 'D' }, | |
{ team: 'Belgium', group: 'E' }, | |
{ team: 'Portugal', group: 'F' } | |
] | |
TIER_2_TEAMS = [ | |
{ team: 'Switzerland', group: 'A' }, | |
{ team: 'Russia', group: 'B' }, | |
{ team: 'Poland', group: 'C' }, | |
{ team: 'Croatia', group: 'D' }, | |
{ team: 'Italy', group: 'E' }, | |
{ team: 'Austria', group: 'F' } | |
] | |
TIER_3_TEAMS = [ | |
{ team: 'Romania', group: 'A' }, | |
{ team: 'Wales', group: 'B' }, | |
{ team: 'Ukraine', group: 'C' }, | |
{ team: 'Turkey', group: 'D' }, | |
{ team: 'Sweden', group: 'E' }, | |
{ team: 'Iceland', group: 'F' } | |
] | |
TIER_4_TEAMS = [ | |
{ team: 'Albania', group: 'A' }, | |
{ team: 'Slovakia', group: 'B' }, | |
{ team: 'Northern Ireland', group: 'C' }, | |
{ team: 'Czech Republic', group: 'D' }, | |
{ team: 'Republic of Ireland', group: 'E' }, | |
{ team: 'Hungary', group: 'F' } | |
] | |
PLAYERS = ['Eoin', 'Niall', 'Dave', 'Shane' , 'Dan', 'Dylan'] | |
def generateTeams(seed) | |
pools = [TIER_1_TEAMS.dup, TIER_2_TEAMS.dup, TIER_3_TEAMS.dup, TIER_4_TEAMS.dup] | |
validSequence = false | |
result = nil | |
while (validSequence == false) do | |
Rails.logger.info("Generating...") | |
pools.each{ |pool| seed += 1; pool.shuffle!(random: Random.new(seed)) } | |
result = PLAYERS.each_with_index.map do |player, index| | |
{ "#{player}": [pools.first[index], pools.second[index], pools.third[index], pools.fourth[index]]} | |
end | |
validSequence = result.all? do |player| | |
player.values.first.map{ |pool| pool[:group] }.uniq.count == 4 | |
end | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment