Using JavaScript / jQuery to create fixtures

I am putting together a tool for a colleague to help build a good 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 the math / brain-block processing.

Let's say I have 4 teams and they all have to play each other at home and away. Using this tool - http://www.fixturelist.com/ - I see that the 4 team home and distance mount will take 6 weeks / rounds / whatever. However, for my life, I cannot figure out how this was programmatically designed.

Can anyone explain the logic to handle this?

For information, I would use this existing tool, but there are other factors / functions in which I have to work, and therefore doing my own job. If I could figure out how to represent this logic!

+2


source to share


1 answer


In your example of 4 commands, name them a, b, c and d:

  • a should play b, c, d
  • b must play c, d (play against already included in games)
  • c must play d (play against already included in games, against b already included in games b)

If they need to play at home and away, then 12 games. You can play no more than 4/2 = 2 games per week, so 6 weeks.

With teams, n

you need games x

where:



x = ((n-1 + n-2 + n-3 ...) * 2)

      

It takes y

weeks where:

y = x/(n/2) = 2x/n

      

This can be simplified with an arithmetic series quite easily, or calculated with a for loop if you want.

0


source







All Articles