views:

260

answers:

1

Hi, I need to calculate the number of matches in a Swiss system tournament, is there any library in php that can help me?

+1  A: 

From the description on Wikipedia, it seems that it is determining the pairings that is the difficult task. The total number of matches just depends on how many rounds are played. If we go with the suggestion that the number of rounds is determined by the base-2 logarithm of the number of entrants (n), then the number of matches (m) is as follows:

m = ceil(log2 n) * floor(n / 2)

So for 10 players you need 4 rounds, with 5 matches in each, hence 20 matches. With an odd number of players there would be a bye, so for 11 players the number of matches is the same.

Dan Dyer