I’m putting together a tool for a colleague which helps to create a nice fixture list. I got about 2/3 through the tool, collecting various data … and then I hit a brick wall. It’s less of a JavaScript problem and more of a maths/processing brainblock.
Lets say I have 4 teams, and they all need to play each other at home and away. Using this tool – http://www.fixturelist.com/ – I can see that a home and away fixture with 4 teams would take 6 weeks/rounds/whatever. For the life of me, though, I can’t work out how that was programmatically worked out.
Can someone explain the logic to process this?
For info, I would use this existing tool, but there are other factors/features that I need to work in, hence doing a custom job. If only I could understand how to represent that logic!
In your example of 4 teams, call them a, b, c and d:
If they need to play at home and away, that’s 12 games. You can play at most 4/2 = 2 games a week, so that’s 6 weeks.
With
nteams you needxgames, where:This takes
yweeks, where:This can be simplified with an arithmetic series fairly easily, or calculated with a for loop if you want.