For those of you who are unfamiliar, Kirkman's Schoolgirl Problem goes as follows:
Fifteen young ladies in a school walk out three abreast for seven days in succession: it is required to arrange them daily so that no two shall walk twice abreast.
We could look at this like a nested 3 by 5 list (or matrix):
[[a,b,c]
[d,e,f]
[g,h,i]
[j,k,l]
[m,n,o]]
Essentially, the goal of the original problem is to figure out 7 different ways to arrange the above matrix so that two letters never share a row more than once. From MathWorld (linked above), we find this solution:
[[a,b,c] [[a,d,h] [[a,e,m] [[a,f,i] [[a,g,l] [[a,j,n] [[a,k,o]
[d,e,f] [b,e,k] [b,h,n] [b,l,o] [b,d,j] [b,i,m] [b,f,g]
[g,h,i] [c,i,o] [c,g,k] [c,h,j] [c,f,m] [c,e,l] [c,d,n]
[j,k,l] [f,l,n] [d,i,l] [d,k,m] [e,h,o] [d,o,g] [e,i,j]
[m,n,o]] [g,j,m]] [f,j,o]] [e,g,n]] [i,k,n]] [f,h,k]] [h,l,m]]
Now, what if there were a different number of schoolgirls? Could there be an eighth day?† This is our challenge.
†In this case no††, but not necessarily for other array dimensions
††We can easily show this, since a
appears in a row with every other letter.
The Challenge:
Given an input of dimensions (rows, than columns) of an array of schoolgirls (i.e. 3 x 5
, 4 x 4
, or [7,6]
, [10,10]
, etc.), output the largest possible set of 'days' that fit the requirements specified above.
Input:
The dimensions for the schoolgirl array (any reasonable input form you wish).
Output:
The largest possible series of arrays fitting the above requirements (any reasonable form).
Test Cases:
Input: [1,1]
Output: [[a]]
Input: [1,2]
Output: [[a,b]]
Input:* [2,1]
Output: [[a]
[b]]
Input: [2,2]
Output: [[a,b] [[a,c] [[a,d]
[c,d]] [b,d]] [b,c]]
Input: [3,3]
Output: [[a,b,c] [[a,d,g] [[a,e,i] [[a,f,h]
[d,e,f] [b,e,h] [b,f,g] [b,d,i]
[g,h,i]] [c,f,i]] [c,d,h]] [c,e,g]]
Input: [5,3]
Output: [[a,b,c] [[a,d,h] [[a,e,m] [[a,f,i] [[a,g,l] [[a,j,n] [[a,k,o]
[d,e,f] [b,e,k] [b,h,n] [b,l,o] [b,d,j] [b,i,m] [b,f,g]
[g,h,i] [c,i,o] [c,g,k] [c,h,j] [c,f,m] [c,e,l] [c,d,n]
[j,k,l] [f,l,n] [d,i,l] [d,k,m] [e,h,o] [d,o,g] [e,i,j]
[m,n,o]] [g,j,m]] [f,j,o]] [e,g,n]] [i,k,n]] [f,h,k]] [h,l,m]]
There may be more than one correct answer.
*Thanks to @Frozenfrank for correcting test case 3: if there is only one column, there can only be one day, since row order does not matter.
This is code-golf competition - shortest answer wins.