One factorization

one_factorization is a function that returns a 1-factorization of a given list of objects. That is, for a list of $n$ objects, it returns $n-1$ ways of pairing up all of the objects such that each pair of objects occurs exactly once (and thus is essentially a 1-factorization of the complete graph on $n$ vertices).

Alternatively, this function can be thought of as scheduling a round-robin tournament: given an even number $n$ of players, it shows how each player can play against every other player by pairs of players playing $n/2$ games concurrently $n-1$ times (which is optimal).

Syntax

 * FAC = one_factorization(N)

Argument descriptions

 * N: Either an even integer, indicating that you would like a 1-factorization of the integers $1, 2, \ldots, N$, or a vector containing an even number of distinct entries, indicating that you would like a 1-factorization of those entries.

A 1-factorization of six objects
The following code generates a 1-factorization of the numbers $1,2,3,4,5,6$:

Each row of the output is a single perfect matching (i.e., a way of pairing up the N objects), which are read "naively" left-to-right. For example, the first row of the output above indicates the following pairing: $\{\{1,6\},\{5,2\},\{4,3\}\}$. The other rows are similar, and each pair occurs exactly once in the entire matrix (e.g., the pair $\{1,3\}$ occurs only in the 2nd row).