# Social squares of prime size

by Richard A. DeVenezia, back to round robin

I call this a social square, and first encountered the problem from an entry in the
guestbook. If you know a more mathematical or formal name, please
let me know.

## Problem

Schedule M x M players to play in M+1 rounds of M teams of M players each, so that every player is paired with every other player only
once.

N = M x M. What if you have N players and N is slightly less than a square N*?

Plan for N^{*}=N+G players, where G is the number of
ghost players. Some teams will have more players than others.

What if you have N players and N is slightly more than a square N*?

Plan for N^{*}=N-X players, where X is the number of excess
players. In the first round, put X players on standby. In subsequent rounds randomly replace X players with those on standby. Some players will play
more (or less) than other players.

## Solution

This culmination of a wandering study of patterns arose from an extravagant algorithm.

Round 0 is 0..N-1 listed column-wise.

Round M is Round 0 transposed.

Round k is Round k-1 after each column j has been rotated by j positions.

PlayerId ( r, t, p ) = p *x* m + ( t + p *x* r ) % m

PlayerId ( m, t, p ) = t *x* m + ( p )

r = round 0..m-1,

t = team 0..m-1

p = player 0..m-1

All row-wise pairings of PlayerIds are distinct over r,t,p only when m is prime.

There may be generators for non-prime m, but I have not found them. The may be proofs indicating which non-prime m are unplannable, but I have not gone looking for them.