**Motivation.** In a team of $n$ people, we had the task to build subteams of a fixed size $k<n$ such that every day, $1$ person of the subteam is replaced by another person in the team, but not in the subteam (so that the new subteam consisted of $k$ again). The question arose if and for what choices of $k$ and $n$ the subteam schedule can be built to contain each choice of $k$ people out of the team exactly once.


**Formal version.** For any set $X$ and positive integer $k$, let $[X]^k$ be the collection of subset of $X$ having $k$ elements. For $n\in\mathbb{N}$ let $[n] =\{1,\ldots,n\}$. For integers $1< k < n$ we define a graph $G(n, k)$ by $V(G(n,k)) = [[n]]^k$ and $$E(G(n,k)) = \big\{\{A, B\} : A, B \in [[n]]^k \land |A\cap B| = k-1\big\}.$$
For what choices of $1< k < n$ does $G(n,k)$ have a Hamiltonian path? Bonus question: Replace "path" by "cycle" in the original question. (The bonus question need not be answered for acceptance.)



"Gray code" for building teams
This seems to be possible for all choices of $k$ and $n$. I found a page [here](http://math0.wvstateu.edu/%7Ebaker/cs405/code/RevolvingDoor.html) by Dr. Ronald D. BAKER describing a more than sixty year old 'revolving door algorithm'.



> 
> When enumerating the k-element subsets of and n-set we are implicitly enumerating the partitions of the n-set into parts, one of size s=k and the other of size t=n-k. Hence the problem is often described as the enumeration of (s,t)-combinations. Suppose the think of the set as a collection of people and imagine them being divided into two adjacent rooms, k people in one room with the remaining n-k people in the other room. Now further imagine that there is a **revolving door** connecting the two rooms, and a change consists of an individual from each room entering that revolving door and exchanging sides. This analogy is the source of the moniker revolving door algorithm.
> 
> 
> W. H. Payne created the following algorithm in 1959. The call to **visit** might, for example, output the k-subset or it might do the computations of an algorithm which needs all k-element subsets. Each k-subset is referenced by an **index-list** $c\_k \dots c\_2c\_1$, the indices of the elements belonging to the subset sorted in order. Notice the code makes extensive use of conditionals, the branching command goto and line labels†.
> 
> 
> 
> ```
> algorithm RevDoorSubset(n, k)
>      Array C[1..k+1]
> R1:  for i ← 1 to k do    // initialize C
>         C[i] ← i-1
>      end for
>      C[k+1] ← n
> R2:  visit(C[ ], k)   // Do whatever is needed w/ subset (just print?)
> R3:  if (k is odd)    // the easy cases
>        if ( C[1]+1 < C[2] )                            
>           C[1] ← C[1]+1
>           goto R2
>        else
>            j ← 2
>           goto R4
>        fi
>      else
>        if ( C[1] > 0 )
>           C[1] ← C[1]-1
>           goto R2
>        else
>            j ← 2
>           goto R5
>        fi
>      fi
>     
> R4:  if ( C[j] ≥ j )  // try to decrease C[j]
>        C[j] ← C[j-1]
>        C[j-1] ← j-2
>        goto R2
>      else
>        j ← j+1
>      fi
> R5:  if ( C[j] + 1 < C[j+1] )     // try to increase C[j]
>        C[j-1] ← C[j]
>        C[j] ← C[j] + 1
>        goto R2
>      else
>        j ← j + 1
>        if ( j ≤ k)
>          goto R4
>        fi
>      fi
>      return
> end
> 
> ```
> 
> 


I've converted the algorithm to JavaScript; I don't think MathOverflow supports [Stack Snippets](https://meta.stackexchange.com/tags/stack-snippets/info) but I've managed to host a working demo [here](https://meta.stackexchange.com/a/327624/295232) in the Sandbox on Meta Stack Exchange. Click the 'Run code snippet' below the code, change the values of $n$ and $k$ and click 'Generate'.


You can also try it online [here](https://jsfiddle.net/Glorfindel83/be7qoj25/6/) in case the Sandbox fails.


It seems this algorithm produces Hamiltonian cycles, but to prove it I'll need some sleep first.


