Skip to content

Instantly share code, notes, and snippets.

@clux
Created June 16, 2014 14:46
Show Gist options
  • Save clux/e6f748c8bd9539d8ae1a to your computer and use it in GitHub Desktop.
Save clux/e6f748c8bd9539d8ae1a to your computer and use it in GitHub Desktop.
groupstage module vs fifa2014
var seeds = [
// top 8 seeds
'BRZ', // brazil
'SPA', // spain
'GER', // germany
'ARG', // argentina
'COL', // columbia
'BEL', // belgium
'URU', // uruguay
'SWI', // switzerland
// bottom seeds
'NED', // netherlands
'ITA', // italy
'ENG', // england
'CHI', // chile
'USA', // united states
'POR', // portugal
'GRE', // greece
'BIH', // bosnia and herzegovina
'CIV', // ivory coast
'CRO', // croatia
'RUS', // russia
'FRA', // france
'ECU', // ecuador
'GHA', // ghana
'MEX', // mexico
'CRC', // costa rica
'ALG', // algeria
'NGA', // nigeria
'HON', // honduras
'JPN', // japan
'IRN', // iran
'KOR', // south korea
'AUS', // australia
'CMR' // cameroon
];
var assert = require('assert');
assert(seeds.length === 8*4, 'have not missed out any teams');
// expected sum of seeds is sum of integers up to seeds.length divided by num groups
var seedSum = (seeds.length*(seeds.length+1)/2) / 8;
console.log('fifa groups 2014:');
var fifaGroups = [
['BRZ', 'MEX', 'CMR', 'CRO'],
['NED', 'CHI', 'AUS', 'SPA'],
['COL', 'CIV', 'JPN', 'GRE'],
['CRC', 'ITA', 'ENG', 'URU'],
['FRA', 'SWI', 'ECU', 'HON'],
['ARG', 'IRN', 'NGA', 'BIH'],
['GER', 'POR', 'GHA', 'USA'],
['BEL', 'ALG', 'RUS', 'KOR']
];
var calculateSum = function (group) {
return group.reduce(function (sum, code) {
var idx = seeds.indexOf(code);
assert(idx >= 0, 'index exists for ' + code);
return sum + (idx + 1);
}, 0);
};
var masterSum = 0;
fifaGroups.forEach(function (group, i) {
var sum = calculateSum(group);
console.log(' Group', (i + 1) + ':', group.join(', '), '( seed sum is ' + sum + ' )');
masterSum += sum;
});
assert(masterSum === seedSum*8, 'we did math correctly');
// so sort by strength:
console.log('Toughest groups:')
fifaGroups.sort(function (g1, g2) {
return calculateSum(g1) - calculateSum(g2);
}).slice(0, 3).forEach(function (group, i) {
var sum = calculateSum(group);
console.log(' #' + (i+1) + ':', group.join(', '), '(' + sum + ')');
});
console.log('\nactually fair groups:');
var GS = require('./');
var gs = new GS(8*4, { groupSize: 4 });
[1,2,3,4,5,6,7,8].forEach(function (g) {
var sum = 0;
var ps = [];
gs.players({ s: g }).forEach(function (p) {
ps.push(seeds[p-1]);
sum += p;
});
console.log(' Group', g + ':', ps.join(', '), '( seed sum is ' + sum + ' )');
});
@clux
Copy link
Author

clux commented Jun 16, 2014

@clux
Copy link
Author

clux commented Jun 16, 2014

Output:

fifa groups 2014:
  Group 1: BRZ, MEX, CMR, CRO ( seed sum is 74 )
  Group 2: NED, CHI, AUS, SPA ( seed sum is 54 )
  Group 3: COL, CIV, JPN, GRE ( seed sum is 65 )
  Group 4: CRC, ITA, ENG, URU ( seed sum is 52 )
  Group 5: FRA, SWI, ECU, HON ( seed sum is 76 )
  Group 6: ARG, IRN, NGA, BIH ( seed sum is 75 )
  Group 7: GER, POR, GHA, USA ( seed sum is 52 )
  Group 8: BEL, ALG, RUS, KOR ( seed sum is 80 )
Toughest groups:
  #1: CRC, ITA, ENG, URU (52)
  #2: GER, POR, GHA, USA (52)
  #3: NED, CHI, AUS, SPA (54)

actually fair groups:
  Group 1: BRZ, NED, CRC, CMR ( seed sum is 66 )
  Group 2: SPA, ITA, MEX, AUS ( seed sum is 66 )
  Group 3: GER, ENG, GHA, KOR ( seed sum is 66 )
  Group 4: ARG, CHI, ECU, IRN ( seed sum is 66 )
  Group 5: COL, USA, FRA, JPN ( seed sum is 66 )
  Group 6: BEL, POR, RUS, HON ( seed sum is 66 )
  Group 7: URU, GRE, CRO, NGA ( seed sum is 66 )
  Group 8: SWI, BIH, CIV, ALG ( seed sum is 66 )

@clux
Copy link
Author

clux commented Jun 16, 2014

Note that this was kind of expected for the FIFA groups. Only the top 8 seeds are actually split properly, the rest are random draws from pots of geographical zones.

What is interesting is that very elaborate measures were taken to ensure fairness, and the result is the above. Not too bad, but not super fair. Group 8 has 53% higher sum of seeds than group 4. This does not say it's 53% easier, but it does imply a difference in skill if one assumes the seeds are solid and based in reality.

If we had taken the perfectly seeded groups, then the groups would arguably be worse due to the greatly varying degree of geographical group proximity (fair group #4 is probably the worst offender).

Was it worth it over just doing the pure mathematical solution?

@clux
Copy link
Author

clux commented Jun 16, 2014

Final note. GroupStage module that generated the fair groups did not just pick ANY combination to ensure the sum was 66. It took one from top 8 (highest tier), one from 9-16 (second tier), one from 17-24 (third tier), and one from 25-32 (bottom tier).

This is always possible to do when the size of each group is the same even number (in this case 4).

@clux
Copy link
Author

clux commented Jun 18, 2014

How bad could it have been? Looking at the draw procedures, it is possible to get the following combination of groups:

var toughestPossible = ['BRZ', 'NED', 'USA', 'ITA']; // seed sum 33
var weakestPossible = ['SWI', 'CMR', 'AUS', 'NGA']; // seed sum 97
// 6 other groups

The toughest one relies on Italy being picked as the extraneous european team and it being matched up with Brazil as the pot X winner. Entirely possible, but obviously much worse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment