Created
June 16, 2014 14:46
-
-
Save clux/e6f748c8bd9539d8ae1a to your computer and use it in GitHub Desktop.
groupstage module vs fifa2014
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
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 + ' )'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How bad could it have been? Looking at the draw procedures, it is possible to get the following combination of 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.